mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-04-23 19:56:24 +02:00
Compare commits
No commits in common. "v6" and "v3.3.1" have entirely different histories.
387
.editorconfig
387
.editorconfig
@ -1,387 +0,0 @@
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
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 = false
|
||||
ij_smart_tabs = false
|
||||
ij_wrap_on_typing = true
|
||||
|
||||
[*.java]
|
||||
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 = 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 = 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 = 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 = 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 = 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 = 1
|
||||
ij_java_blank_lines_after_imports = 1
|
||||
ij_java_blank_lines_after_package = 1
|
||||
ij_java_blank_lines_around_class = 1
|
||||
ij_java_blank_lines_around_field = 0
|
||||
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 = 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 = 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 = 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 = 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
|
||||
ij_java_doc_add_blank_line_after_return = false
|
||||
ij_java_doc_add_p_tag_on_empty_lines = true
|
||||
ij_java_doc_align_exception_comments = true
|
||||
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 = 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 = 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
|
||||
ij_java_else_on_new_line = false
|
||||
ij_java_enum_constants_wrap = split_into_lines
|
||||
ij_java_extends_keyword_wrap = off
|
||||
ij_java_extends_list_wrap = normal
|
||||
ij_java_field_annotation_wrap = split_into_lines
|
||||
ij_java_finally_on_new_line = false
|
||||
ij_java_for_brace_force = always
|
||||
ij_java_for_statement_new_line_after_left_paren = false
|
||||
ij_java_for_statement_right_paren_on_new_line = false
|
||||
ij_java_for_statement_wrap = off
|
||||
ij_java_generate_final_locals = true
|
||||
ij_java_generate_final_parameters = true
|
||||
ij_java_if_brace_force = always
|
||||
ij_java_imports_layout = *, |, javax.**, java.**, |, $*
|
||||
ij_java_indent_case_from_switch = true
|
||||
ij_java_insert_inner_class_imports = false
|
||||
ij_java_insert_override_annotation = true
|
||||
ij_java_keep_blank_lines_before_right_brace = 2
|
||||
ij_java_keep_blank_lines_between_package_declaration_and_header = 2
|
||||
ij_java_keep_blank_lines_in_code = 2
|
||||
ij_java_keep_blank_lines_in_declarations = 2
|
||||
ij_java_keep_control_statement_in_one_line = true
|
||||
ij_java_keep_first_column_comment = true
|
||||
ij_java_keep_indents_on_empty_lines = false
|
||||
ij_java_keep_line_breaks = true
|
||||
ij_java_keep_multiple_expressions_in_one_line = false
|
||||
ij_java_keep_simple_blocks_in_one_line = false
|
||||
ij_java_keep_simple_classes_in_one_line = false
|
||||
ij_java_keep_simple_lambdas_in_one_line = false
|
||||
ij_java_keep_simple_methods_in_one_line = false
|
||||
ij_java_label_indent_absolute = false
|
||||
ij_java_label_indent_size = 0
|
||||
ij_java_lambda_brace_style = end_of_line
|
||||
ij_java_layout_static_imports_separately = true
|
||||
ij_java_line_comment_add_space = false
|
||||
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 = 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 = 100000
|
||||
ij_java_new_line_after_lparen_in_record_header = false
|
||||
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 = 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
|
||||
ij_java_replace_null_check = true
|
||||
ij_java_replace_sum_lambda_with_method_ref = true
|
||||
ij_java_resource_list_new_line_after_left_paren = false
|
||||
ij_java_resource_list_right_paren_on_new_line = false
|
||||
ij_java_resource_list_wrap = off
|
||||
ij_java_rparen_on_new_line_in_record_header = false
|
||||
ij_java_space_after_closing_angle_bracket_in_type_argument = false
|
||||
ij_java_space_after_colon = true
|
||||
ij_java_space_after_comma = true
|
||||
ij_java_space_after_comma_in_type_arguments = true
|
||||
ij_java_space_after_for_semicolon = true
|
||||
ij_java_space_after_quest = true
|
||||
ij_java_space_after_type_cast = true
|
||||
ij_java_space_before_annotation_array_initializer_left_brace = false
|
||||
ij_java_space_before_annotation_parameter_list = false
|
||||
ij_java_space_before_array_initializer_left_brace = false
|
||||
ij_java_space_before_catch_keyword = true
|
||||
ij_java_space_before_catch_left_brace = true
|
||||
ij_java_space_before_catch_parentheses = true
|
||||
ij_java_space_before_class_left_brace = true
|
||||
ij_java_space_before_colon = true
|
||||
ij_java_space_before_colon_in_foreach = true
|
||||
ij_java_space_before_comma = false
|
||||
ij_java_space_before_do_left_brace = true
|
||||
ij_java_space_before_else_keyword = true
|
||||
ij_java_space_before_else_left_brace = true
|
||||
ij_java_space_before_finally_keyword = true
|
||||
ij_java_space_before_finally_left_brace = true
|
||||
ij_java_space_before_for_left_brace = true
|
||||
ij_java_space_before_for_parentheses = true
|
||||
ij_java_space_before_for_semicolon = false
|
||||
ij_java_space_before_if_left_brace = true
|
||||
ij_java_space_before_if_parentheses = true
|
||||
ij_java_space_before_method_call_parentheses = false
|
||||
ij_java_space_before_method_left_brace = true
|
||||
ij_java_space_before_method_parentheses = false
|
||||
ij_java_space_before_opening_angle_bracket_in_type_parameter = false
|
||||
ij_java_space_before_quest = true
|
||||
ij_java_space_before_switch_left_brace = true
|
||||
ij_java_space_before_switch_parentheses = true
|
||||
ij_java_space_before_synchronized_left_brace = true
|
||||
ij_java_space_before_synchronized_parentheses = true
|
||||
ij_java_space_before_try_left_brace = true
|
||||
ij_java_space_before_try_parentheses = true
|
||||
ij_java_space_before_type_parameter_list = false
|
||||
ij_java_space_before_while_keyword = true
|
||||
ij_java_space_before_while_left_brace = true
|
||||
ij_java_space_before_while_parentheses = true
|
||||
ij_java_space_inside_one_line_enum_braces = false
|
||||
ij_java_space_within_empty_array_initializer_braces = false
|
||||
ij_java_space_within_empty_method_call_parentheses = false
|
||||
ij_java_space_within_empty_method_parentheses = false
|
||||
ij_java_spaces_around_additive_operators = true
|
||||
ij_java_spaces_around_assignment_operators = true
|
||||
ij_java_spaces_around_bitwise_operators = true
|
||||
ij_java_spaces_around_equality_operators = true
|
||||
ij_java_spaces_around_lambda_arrow = true
|
||||
ij_java_spaces_around_logical_operators = true
|
||||
ij_java_spaces_around_method_ref_dbl_colon = false
|
||||
ij_java_spaces_around_multiplicative_operators = true
|
||||
ij_java_spaces_around_relational_operators = true
|
||||
ij_java_spaces_around_shift_operators = true
|
||||
ij_java_spaces_around_type_bounds_in_type_parameters = true
|
||||
ij_java_spaces_around_unary_operator = false
|
||||
ij_java_spaces_within_angle_brackets = false
|
||||
ij_java_spaces_within_annotation_parentheses = false
|
||||
ij_java_spaces_within_array_initializer_braces = false
|
||||
ij_java_spaces_within_braces = false
|
||||
ij_java_spaces_within_brackets = false
|
||||
ij_java_spaces_within_cast_parentheses = false
|
||||
ij_java_spaces_within_catch_parentheses = false
|
||||
ij_java_spaces_within_for_parentheses = false
|
||||
ij_java_spaces_within_if_parentheses = false
|
||||
ij_java_spaces_within_method_call_parentheses = false
|
||||
ij_java_spaces_within_method_parentheses = false
|
||||
ij_java_spaces_within_parentheses = false
|
||||
ij_java_spaces_within_switch_parentheses = false
|
||||
ij_java_spaces_within_synchronized_parentheses = false
|
||||
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 = true
|
||||
ij_java_ternary_operation_wrap = on_every_item
|
||||
ij_java_test_name_suffix = Test
|
||||
ij_java_throws_keyword_wrap = off
|
||||
ij_java_throws_list_wrap = normal
|
||||
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 = 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 = true
|
||||
ij_java_wrap_long_lines = 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
|
||||
|
||||
[.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
|
||||
|
||||
[{*.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
|
||||
|
||||
|
||||
[*.json]
|
||||
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 = false
|
||||
ij_yaml_spaces_within_braces = true
|
||||
ij_yaml_spaces_within_brackets = true
|
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -1,4 +0,0 @@
|
||||
* text=auto
|
||||
|
||||
*.java text
|
||||
*.jar binary
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -1 +0,0 @@
|
||||
* @IntellectualSites/plotsquared-team
|
2
.github/CONTRIBUTING.md
vendored
Normal file
2
.github/CONTRIBUTING.md
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
### Bugs
|
||||
Please provide a `/plot debugpaste` if you are reporting a bug.
|
12
.github/ISSUE_TEMPLATE.md
vendored
Normal file
12
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# Bug report template (clear for feature request)
|
||||
**Debug paste link**:
|
||||
|
||||
**Description of the problem:**
|
||||
|
||||
**How to replicate**:
|
||||
|
||||
Make sure you've completed the following steps (put X inside of brackets):
|
||||
- [ ] Include `/plot debugpaste`
|
||||
- [ ] Made sure there aren't duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues)
|
||||
- [ ] Made sure you're using an updated version of PlotSquared
|
||||
- [ ] Made sure the bug/error isn't caused by any other plugin
|
105
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
105
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -1,105 +0,0 @@
|
||||
name: Bug report
|
||||
description: Create a report to help us improve
|
||||
labels: 'Requires Testing'
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report for PlotSquared! Fill out the following form to your best ability to help us fix the problem.
|
||||
Only use this if you're absolutely sure that you found a bug and can reproduce it. For anything else, use: [our Discord server](https://discord.gg/intellectualsites) or [the wiki](https://intellectualsites.github.io/plotsquared-documentation/).
|
||||
Do NOT use the public issue tracker to report security vulnerabilities! They are disclosed using [this](https://forms.gle/btgdRn9yhGtzEiGW8) form!
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Server Implementation
|
||||
description: Which server Implementation are you using? If your server implementation is not listed, it is not supported. Switch to a supported version first.
|
||||
multiple: false
|
||||
options:
|
||||
- Paper
|
||||
- Spigot
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: Server Version
|
||||
description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first.
|
||||
multiple: false
|
||||
options:
|
||||
- '1.19.3'
|
||||
- '1.19.2'
|
||||
- '1.19.1'
|
||||
- '1.19'
|
||||
- '1.18.2'
|
||||
- '1.18.1'
|
||||
- '1.17.1'
|
||||
- '1.16.5'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the bug
|
||||
description: A clear and concise description of what the bug is.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: To Reproduce
|
||||
description: Steps to reproduce this behaviour
|
||||
placeholder: |
|
||||
1. Go to '...'
|
||||
2. Click on '...'
|
||||
3. Scroll down to '...'
|
||||
4. See error
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Expected behaviour
|
||||
description: A clear and concise description of what you expected to happen.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Screenshots / Videos
|
||||
description: If applicable, add screenshots to help explain your problem.
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Error log (if applicable)
|
||||
description: If you are reporting a console error, upload any relevant log excerpts to either https://paste.gg/ or https://gist.github.com, save and the paste the link in this box.
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Plot Debugpaste
|
||||
description: Run `/plot debugpaste` in your console or ingame and provide the output link here.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: PlotSquared Version
|
||||
description: What version of PlotSquared are you running? (`/version PlotSquared`)
|
||||
placeholder: "For example: PlotSquared version 5.13.11-Premium"
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Checklist
|
||||
description: Make sure you have followed each of the steps outlined here.
|
||||
options:
|
||||
- label: I have included a Plot debugpaste.
|
||||
required: true
|
||||
- label: I am using the newest build from https://www.spigotmc.org/resources/77506/ and the issue still persists.
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Anything else?
|
||||
description: You can provide additional context below.
|
8
.github/ISSUE_TEMPLATE/config.yml
vendored
8
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,8 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: IntellectualSites Discord
|
||||
url: https://discord.gg/intellectualsites
|
||||
about: Our support Discord, please ask questions and seek support here.
|
||||
- name: PlotSquared Wiki
|
||||
url: https://intellectualsites.github.io/plotsquared-documentation/
|
||||
about: Take a look at the wiki page for instructions how to setup PlotSquared and use its commands.
|
29
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
29
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,29 +0,0 @@
|
||||
name: Feature request
|
||||
description: Suggest an idea for this project
|
||||
labels: 'Enhancement'
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this feature request for PlotSquared! Fill out the following form to your best ability to help us understand your feature request and greately improve the change of it getting added.
|
||||
For anything else than a feature request, use: [our Discord server](https://discord.gg/intellectualsites) or [the wiki](https://intellectualsites.github.io/plotsquared-documentation/).
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: What feature do you want to see added?
|
||||
description: A clear and concise description of your feature request.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Are there any alternatives?
|
||||
description: List any alternatives you might have tried
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Anything else?
|
||||
description: You can provide additional context below.
|
1
.github/release-drafter.yml
vendored
1
.github/release-drafter.yml
vendored
@ -1 +0,0 @@
|
||||
_extends: .github
|
18
.github/stale.yml
vendored
18
.github/stale.yml
vendored
@ -1,18 +0,0 @@
|
||||
daysUntilStale: 30
|
||||
daysUntilClose: 7
|
||||
only: issues
|
||||
exemptLabels:
|
||||
- "Bug"
|
||||
- "Enhancement"
|
||||
- "Approved"
|
||||
- "Priority"
|
||||
- "Under investigation"
|
||||
staleLabel: "resolution: stale"
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. If the issue is still present and can be reproduced, please let the team know.
|
||||
Thank you for your contributions.
|
||||
closeComment: >
|
||||
This issue has been automatically closed because it has not had activity in
|
||||
a long time. If the issue still applies to the most recent supported
|
||||
version, please reply to this issue and the team will reopen it.
|
@ -1,24 +0,0 @@
|
||||
name: Announce release on discord
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
jobs:
|
||||
send_announcement:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: send custom message with args
|
||||
env:
|
||||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
DISCORD_USERNAME: PlotSquared Release
|
||||
DISCORD_AVATAR: https://raw.githubusercontent.com/IntellectualSites/Assets/main/plugins/PlotSquared/PlotSquared.png
|
||||
uses: Ilshidur/action-discord@08d9328877d6954120eef2b07abbc79249bb6210 # ratchet:Ilshidur/action-discord@0.3.2
|
||||
with:
|
||||
args: |
|
||||
"<@&525015541815967744> <@&679322738552471574> <@&699293353862496266>"
|
||||
""
|
||||
"<:plotsquared:730750385886593039> **PlotSquared ${{ github.event.release.tag_name }} has been released!**"
|
||||
""
|
||||
"Click here to view changelog: https://github.com/IntellectualSites/PlotSquared/releases/tag/${{ github.event.release.tag_name }}"
|
||||
""
|
||||
"The download is available at:"
|
||||
"- Spigot: <https://www.spigotmc.org/resources/77506/>"
|
21
.github/workflows/build-pr.yml
vendored
21
.github/workflows/build-pr.yml
vendored
@ -1,21 +0,0 @@
|
||||
name: Build PR
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
build_pr:
|
||||
if: github.repository_owner == 'IntellectualSites'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@55e685c48d84285a5b0418cd094606e199cca3b6 # v1
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
- name: Clean Build
|
||||
run: ./gradlew clean build
|
67
.github/workflows/build.yml
vendored
67
.github/workflows/build.yml
vendored
@ -1,67 +0,0 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v6
|
||||
jobs:
|
||||
build:
|
||||
if: github.repository_owner == 'IntellectualSites'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@55e685c48d84285a5b0418cd094606e199cca3b6 # v1
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
- name: Clean Build
|
||||
run: ./gradlew clean build
|
||||
- name: Determine release status
|
||||
if: ${{ runner.os == 'Linux' }}
|
||||
run: |
|
||||
if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then
|
||||
echo "STATUS=snapshot" >> $GITHUB_ENV
|
||||
else
|
||||
echo "STATUS=release" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Publish Release
|
||||
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v6'}}
|
||||
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
|
||||
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
|
||||
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
|
||||
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
|
||||
- name: Publish Snapshot
|
||||
if: ${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v6' }}
|
||||
run: ./gradlew publishToSonatype
|
||||
env:
|
||||
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
|
||||
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
|
||||
- name: Publish core javadoc
|
||||
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v6'}}
|
||||
uses: cpina/github-action-push-to-another-repository@0a14457bb28b04dfa1652e0ffdfda866d2845c73 # main
|
||||
env:
|
||||
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
||||
with:
|
||||
source-directory: 'Core/build/docs/javadoc'
|
||||
destination-github-username: 'IntellectualSites'
|
||||
destination-repository-name: 'plotsquared-javadocs'
|
||||
user-email: ${{ secrets.USER_EMAIL }}
|
||||
target-branch: main
|
||||
target-directory: core
|
||||
- name: Publish bukkit javadoc
|
||||
if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/v6'}}
|
||||
uses: cpina/github-action-push-to-another-repository@0a14457bb28b04dfa1652e0ffdfda866d2845c73 # main
|
||||
env:
|
||||
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
||||
with:
|
||||
source-directory: 'Bukkit/build/docs/javadoc'
|
||||
destination-github-username: 'IntellectualSites'
|
||||
destination-repository-name: 'plotsquared-javadocs'
|
||||
user-email: ${{ secrets.USER_EMAIL }}
|
||||
target-branch: main
|
||||
target-directory: bukkit
|
28
.github/workflows/codeql.yml
vendored
28
.github/workflows/codeql.yml
vendored
@ -1,28 +0,0 @@
|
||||
name: "CodeQL"
|
||||
on:
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [v6]
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: ['java']
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@32dc499307d133bb5085bae78498c0ac2cf762d5 # v2
|
17
.github/workflows/release-drafter.yml
vendored
17
.github/workflows/release-drafter.yml
vendored
@ -1,17 +0,0 @@
|
||||
name: draft release
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v6
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
pull_request_target:
|
||||
types: [opened, reopened, synchronize]
|
||||
jobs:
|
||||
update_release_draft:
|
||||
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: release-drafter/release-drafter@v5
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
271
.gitignore
vendored
271
.gitignore
vendored
@ -1,139 +1,134 @@
|
||||
### Others ###
|
||||
*.cmd
|
||||
*.sh
|
||||
*.prefs
|
||||
Core/build
|
||||
|
||||
### Maven ###
|
||||
/mvn
|
||||
/target/lib
|
||||
/target/maven-archiver
|
||||
/target/classes
|
||||
/target/maven-status
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
out/
|
||||
|
||||
|
||||
### Java ###
|
||||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
|
||||
*.iml
|
||||
|
||||
## Directory-based project format:
|
||||
/.idea/*
|
||||
!/.idea/icon.svg
|
||||
# if you remove the above rule, at least ignore the following:
|
||||
|
||||
# User-specific stuff:
|
||||
# .idea/workspace.xml
|
||||
# .idea/tasks.xml
|
||||
# .idea/dictionaries
|
||||
# .idea/shelf
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
# .idea/dataSources.ids
|
||||
# .idea/dataSources.xml
|
||||
# .idea/sqlDataSources.xml
|
||||
# .idea/dynamic.xml
|
||||
# .idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
# .idea/gradle.xml
|
||||
# .idea/libraries
|
||||
.gradle
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
# .idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
*.pydevproject
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
### Others ###
|
||||
*.bat
|
||||
*.cmd
|
||||
*.sh
|
||||
*.prefs
|
||||
Sponge/build
|
||||
Core/build
|
||||
Bukkit/build
|
||||
|
||||
### Maven ###
|
||||
/target/lib
|
||||
/target/maven-archiver
|
||||
/target/classes
|
||||
/target/maven-status
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
|
||||
|
||||
### Java ###
|
||||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
|
||||
*.iml
|
||||
|
||||
## Directory-based project format:
|
||||
.idea/
|
||||
# if you remove the above rule, at least ignore the following:
|
||||
|
||||
# User-specific stuff:
|
||||
# .idea/workspace.xml
|
||||
# .idea/tasks.xml
|
||||
# .idea/dictionaries
|
||||
# .idea/shelf
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
# .idea/dataSources.ids
|
||||
# .idea/dataSources.xml
|
||||
# .idea/sqlDataSources.xml
|
||||
# .idea/dynamic.xml
|
||||
# .idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
# .idea/gradle.xml
|
||||
# .idea/libraries
|
||||
.gradle
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
# .idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
*.pydevproject
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
/target/
|
||||
checkstyle.xml
|
||||
classes/
|
||||
*.bat
|
||||
|
||||
# Other
|
||||
docs/
|
||||
build/
|
||||
|
||||
.DS_Store
|
||||
|
50
.idea/icon.svg
generated
50
.idea/icon.svg
generated
@ -1,50 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.1" id="svg2" xml:space="preserve" width="4000" height="3333.3333" viewBox="0 0 4000 3333.3333" sodipodi:docname="PlotSquared.ai">
|
||||
<metadata id="metadata8">
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs id="defs6">
|
||||
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath18">
|
||||
<path d="M 0,2500 H 3000 V 0 H 0 Z" id="path16" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<sodipodi:namedview pagecolor="#ffffff" bordercolor="#666666" borderopacity="1" objecttolerance="10" gridtolerance="10" guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="640" inkscape:window-height="480" id="namedview4" />
|
||||
<g id="g10" inkscape:groupmode="layer" inkscape:label="PlotSquared" transform="matrix(1.3333333,0,0,-1.3333333,0,3333.3333)">
|
||||
<g id="g12">
|
||||
<g id="g14" clip-path="url(#clipPath18)">
|
||||
<g id="g20" transform="translate(1486.1511,2242.6453)">
|
||||
<path d="m 0,0 c 16.533,10.846 33.211,21.453 50.104,31.699 78.972,-48.281 153.985,-102.704 227.269,-159.144 148.61,-115.422 287.884,-243.01 414.393,-382.333 111.39,-122.861 212.751,-255.152 298.898,-396.971 52.744,-87.322 100.544,-177.884 139.514,-272.214 -11.638,-3.551 -23.108,-7.655 -34.362,-12.286 l -0.24,0.288 c -11.135,12.982 -24.141,24.212 -34.915,37.506 -22.557,23.013 -45.425,45.737 -68.03,68.678 -19.725,20.253 -40.601,39.45 -58.958,60.974 -36.355,36.451 -72.517,73.093 -108.944,109.471 -22.628,26.013 -48.064,49.385 -71.965,74.197 -19.029,19.485 -38.706,38.346 -57.519,57.999 -12.166,14.998 -26.684,27.716 -39.93,41.658 -27.668,27.524 -54.903,55.479 -82.571,82.979 -23.924,27.956 -51.664,52.264 -76.692,79.164 -4.68,4.487 -8.855,10.774 -15.886,11.326 -22.34,34.027 -58.311,57.327 -97.377,67.502 -104.312,99.153 -215.487,191.202 -332.661,274.782 -117.942,-83.94 -229.476,-176.781 -334.484,-276.39 -26.684,-0.024 -53.368,0.024 -80.076,-0.024 0.024,-26.564 0.048,-53.104 0,-79.668 -72.229,-73.021 -139.491,-150.937 -202.385,-232.092 -63.758,-82.619 -121.973,-169.51 -173.541,-260.264 131.932,-69.061 257.864,-149.521 375.926,-240.275 0.096,-26.444 -0.12,-52.888 0.096,-79.332 l 0.744,-0.984 c 20.109,-24.14 43.409,-45.233 65.126,-67.861 15.118,-15.382 30.571,-30.404 45.569,-45.881 17.565,-20.733 37.698,-39.042 56.607,-58.503 19.917,-20.781 41.25,-40.218 59.967,-62.151 29.156,-29.299 58.167,-58.815 87.515,-87.922 29.155,-33.043 61.502,-63.111 92.169,-94.738 13.726,-12.67 25.124,-27.571 38.634,-40.457 25.029,-25.365 50.129,-50.657 75.325,-75.853 -37.914,-51.208 -73.741,-103.952 -107.192,-158.183 -167.83,273.317 -397.235,507.305 -662.37,687.158 -81.875,55.335 -167.23,105.584 -255.681,149.641 -52.815,26.276 -106.831,50.248 -162.239,70.381 99.393,233.628 242.795,446.715 410.289,636.79 93.562,106.088 194.634,205.433 301.466,298.13 C -217.335,-155.808 -111.439,-73.789 0,0" style="fill:#062f4c;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path22" />
|
||||
</g>
|
||||
<g id="g24" transform="translate(1201.7948,1741.5303)">
|
||||
<path d="M 0,0 C 105.008,99.609 216.543,192.45 334.485,276.39 451.659,192.81 562.833,100.76 667.146,1.608 c -34.987,8.83 -71.51,9.718 -107.264,6.431 -41.202,-4.296 -82.907,-19.077 -112.543,-48.953 -33.019,-32.155 -49.456,-77.604 -55.311,-122.501 -28.124,27.908 -56.104,55.983 -84.035,84.083 -2.976,2.976 -6.839,4.823 -10.391,6.911 -19.029,26.348 -45.953,46.673 -76.62,57.495 C 187.555,-2.472 151.513,-0.12 116.166,0 Z" style="fill:#4c8fcc;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path26" />
|
||||
</g>
|
||||
<g id="g28" transform="translate(919.3342,1429.7462)">
|
||||
<path d="m 0,0 c 62.894,81.156 130.156,159.072 202.385,232.092 0.048,-244.21 0.024,-488.421 0,-732.631 C 84.323,-409.785 -41.61,-329.325 -173.541,-260.264 -121.973,-169.51 -63.758,-82.619 0,0" style="fill:#4c8fcc;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path30" />
|
||||
</g>
|
||||
<g id="g32" transform="translate(1649.134,1700.6166)">
|
||||
<path d="m 0,0 c 29.635,29.875 71.341,44.657 112.543,48.952 35.754,3.288 72.277,2.4 107.263,-6.431 39.066,-10.174 75.037,-33.474 97.377,-67.501 11.879,-17.661 20.181,-37.411 26.42,-57.687 10.871,-38.802 11.95,-79.356 11.446,-119.358 -44.345,-0.072 -88.69,0.048 -133.035,-0.072 -1.032,30.907 3.263,63.686 -10.175,92.626 -9.526,20.325 -32.107,31.243 -53.751,32.131 -21.453,1.44 -45.065,-4.32 -59.175,-21.597 -12.79,-15.861 -15.382,-37.002 -16.558,-56.655 -1.295,-29.132 3.696,-59.031 17.518,-84.923 16.821,-30.619 39.378,-57.783 64.526,-81.9 31.387,-32.634 67.501,-60.374 97.857,-94.041 27.332,-28.988 51.256,-61.479 68.005,-97.785 20.541,-41.13 26.972,-87.827 25.82,-133.372 -0.912,-32.107 -5.231,-64.406 -16.149,-94.737 -11.59,-31.699 -31.123,-61.047 -58.335,-81.371 -25.124,-19.125 -55.696,-29.852 -86.651,-34.771 -49.552,-6.743 -101.888,-4.847 -148.465,14.854 -35.227,14.829 -64.238,42.689 -81.708,76.548 -20.996,40.242 -27.115,86.339 -27.259,131.212 0.048,17.829 0,35.658 0.048,53.463 44.345,0.048 88.69,-0.023 133.059,0.048 1.728,-35.538 -4.055,-72.06 5.663,-106.807 5.783,-22.173 26.204,-37.794 48.185,-41.754 20.733,-3.431 43.577,-2.015 61.622,9.791 15.502,9.43 23.949,26.78 26.78,44.225 5.903,35.922 1.872,74.293 -15.381,106.688 -16.918,30.595 -39.474,57.711 -64.55,81.899 -33.187,34.099 -71.173,63.254 -102.585,99.081 -26.756,28.867 -49.408,61.646 -65.486,97.641 -24.572,52.48 -26.731,112.422 -20.18,169.102 C -49.456,-77.604 -33.019,-32.155 0,0" style="fill:#feeeee;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path34" />
|
||||
</g>
|
||||
<g id="g36" transform="translate(1262.7214,1613.126)">
|
||||
<path d="m 0,0 v -301.13 c 23.204,0.024 46.409,-0.048 69.613,0.024 18.525,0.288 38.202,6.575 50.153,21.429 12.43,17.277 13.917,39.522 14.613,60.111 0.024,43.985 -0.048,87.994 0.024,131.979 -0.48,23.637 -0.983,50.369 -17.277,69.23 C 104.864,-5.711 86.867,-0.24 69.589,0 46.385,0.048 23.204,0.024 0,0 m -141.002,128.38 c 26.708,0.048 53.392,0 80.075,0.024 H 55.24 c 35.346,-0.12 71.389,-2.471 104.815,-14.925 30.668,-10.823 57.592,-31.148 76.621,-57.496 26.852,-39.09 36.69,-87.202 38.058,-133.947 0.024,-48.833 0.096,-97.689 -0.024,-146.521 -1.728,-47.993 -11.974,-97.953 -41.514,-136.971 -22.748,-30.644 -57.495,-50.801 -94.281,-59.583 -45.377,-11.878 -92.578,-6.791 -138.891,-7.847 -0.072,-111.799 0,-223.574 -0.024,-335.373 -13.942,0 -27.86,0.024 -41.778,-0.024 -32.802,0.072 -65.605,0 -98.384,0.048 l -0.744,0.984 c -0.216,26.444 0,52.888 -0.096,79.332 0.024,244.211 0.048,488.421 0,732.632 0.048,26.563 0.024,53.103 0,79.667" style="fill:#feeeee;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path38" />
|
||||
</g>
|
||||
<g id="g40" transform="translate(1966.3174,1675.6364)">
|
||||
<path d="m 0,0 c 7.031,-0.552 11.206,-6.839 15.885,-11.326 25.029,-26.9 52.768,-51.208 76.693,-79.164 27.667,-27.5 54.903,-55.456 82.571,-82.979 13.246,-13.942 27.764,-26.66 39.93,-41.658 18.813,-19.653 38.49,-38.514 57.519,-57.999 23.9,-24.812 49.337,-48.185 71.965,-74.197 36.427,-36.378 72.589,-73.02 108.943,-109.471 18.358,-21.524 39.234,-40.722 58.959,-60.974 22.605,-22.941 45.473,-45.665 68.03,-68.678 10.774,-13.294 23.78,-24.524 34.914,-37.506 -103.904,-41.97 -203.488,-94.114 -298.922,-152.761 -246.994,-152.28 -466.224,-350.298 -639.333,-583.398 -25.197,25.196 -50.297,50.488 -75.325,75.852 -13.51,12.886 -24.908,27.788 -38.634,40.458 -30.667,31.627 -63.014,61.695 -92.17,94.738 -29.347,29.107 -58.359,58.623 -87.514,87.922 -18.717,21.933 -40.05,41.37 -59.967,62.151 -18.909,19.461 -39.042,37.77 -56.607,58.503 -14.998,15.477 -30.452,30.499 -45.569,45.88 -21.717,22.629 -45.017,43.722 -65.126,67.862 32.779,-0.048 65.582,0.024 98.384,-0.048 114.391,-98.097 220.407,-205.984 315.384,-322.99 92.914,114.318 196.242,220.022 307.753,316.271 30.955,4.919 61.526,15.646 86.65,34.771 27.212,20.325 46.745,49.672 58.335,81.371 107.312,77.988 219.327,149.929 337.509,210.376 -35.299,64.67 -75.829,126.437 -118.254,186.643 C 176.253,-228.037 104.24,-140.115 26.42,-57.687 20.181,-37.41 11.878,-17.661 0,0" style="fill:#042338;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path42" />
|
||||
</g>
|
||||
<g id="g44" transform="translate(1499.3971,1669.1094)">
|
||||
<path d="m 0,0 c 3.551,-2.088 7.415,-3.935 10.39,-6.911 27.932,-28.1 55.912,-56.175 84.036,-84.083 -6.551,-56.679 -4.392,-116.622 20.18,-169.102 16.078,-35.994 38.73,-68.774 65.486,-97.641 31.412,-35.826 69.398,-64.982 102.585,-99.081 25.076,-24.188 47.632,-51.304 64.55,-81.899 17.253,-32.395 21.284,-70.765 15.381,-106.688 -2.831,-17.445 -11.278,-34.794 -26.78,-44.225 -18.045,-11.806 -40.889,-13.222 -61.622,-9.79 -21.981,3.959 -42.402,19.58 -48.185,41.753 -9.718,34.747 -3.935,71.269 -5.663,106.808 -44.369,-0.072 -88.714,0 -133.059,-0.048 -0.048,-17.806 0,-35.635 -0.048,-53.464 0.144,-44.873 6.263,-90.97 27.259,-131.212 17.47,-33.859 46.481,-61.718 81.708,-76.548 46.577,-19.701 98.913,-21.597 148.465,-14.854 -111.511,-96.249 -214.839,-201.953 -307.753,-316.271 -94.977,117.006 -200.993,224.893 -315.383,322.99 13.918,0.048 27.836,0.024 41.777,0.024 0.024,111.799 -0.048,223.574 0.024,335.372 46.313,1.056 93.514,-4.031 138.891,7.847 36.786,8.783 71.533,28.94 94.282,59.583 29.539,39.018 39.785,88.978 41.513,136.971 0.12,48.833 0.048,97.689 0.024,146.522 C 36.69,-87.203 26.852,-39.09 0,0" style="fill:#1c72ba;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path46" />
|
||||
</g>
|
||||
<g id="g48" transform="translate(1748.0469,1601.6797)">
|
||||
<path d="M 0,0 C 14.11,17.277 37.722,23.036 59.175,21.597 80.82,20.709 103.4,9.791 112.927,-10.534 c 13.438,-28.94 9.142,-61.719 10.174,-92.626 44.345,0.12 88.691,0 133.036,0.072 0.504,40.002 -0.576,80.556 -11.447,119.358 77.82,-82.428 149.833,-170.35 215.583,-262.664 42.426,-60.207 82.956,-121.973 118.254,-186.643 -118.182,-60.447 -230.196,-132.388 -337.508,-210.376 10.918,30.331 15.238,62.63 16.149,94.737 1.152,45.545 -5.279,92.242 -25.82,133.372 -16.749,36.306 -40.673,68.797 -68.005,97.785 -30.355,33.667 -66.47,61.406 -97.857,94.041 -25.148,24.117 -47.705,51.28 -64.526,81.9 -13.822,25.892 -18.813,55.791 -17.517,84.923 C -15.382,-37.002 -12.79,-15.862 0,0" style="fill:#1c72ba;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path50" />
|
||||
</g>
|
||||
<g id="g52" transform="translate(1262.7214,1613.126)">
|
||||
<path d="m 0,0 c 23.204,0.024 46.385,0.048 69.589,0 17.278,-0.24 35.275,-5.711 47.537,-18.357 16.294,-18.861 16.797,-45.593 17.277,-69.23 -0.072,-43.985 0,-87.994 -0.024,-131.979 -0.696,-20.589 -2.183,-42.834 -14.613,-60.111 -11.951,-14.854 -31.628,-21.141 -50.153,-21.429 -23.204,-0.072 -46.409,0 -69.613,-0.024 z" style="fill:#1c72ba;fill-opacity:1;fill-rule:nonzero;stroke:none" id="path54" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 11 KiB |
35
Bukkit/build.gradle
Normal file
35
Bukkit/build.gradle
Normal file
@ -0,0 +1,35 @@
|
||||
dependencies {
|
||||
compile project(':Core')
|
||||
compile 'org.bukkit:bukkit:1.9-R0.1-SNAPSHOT'
|
||||
compile 'net.milkbowl.vault:VaultAPI:1.5'
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
targetCompatibility = 1.7
|
||||
|
||||
processResources {
|
||||
from('src/main/resources') {
|
||||
include 'plugin.yml'
|
||||
expand(
|
||||
name: project.parent.name,
|
||||
version: project.parent.version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
// We only want the shadow jar produced
|
||||
jar.enabled = false
|
||||
shadowJar {
|
||||
dependencies {
|
||||
include(dependency(':Core'))
|
||||
}
|
||||
archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
|
||||
destinationDir = file '../target'
|
||||
}
|
||||
shadowJar.doLast {
|
||||
task ->
|
||||
ant.checksum file: task.archivePath
|
||||
}
|
||||
|
||||
build.dependsOn(shadowJar);
|
@ -1,116 +0,0 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "PlaceholderAPI"
|
||||
url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "PaperMC"
|
||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "EssentialsX"
|
||||
url = uri("https://repo.essentialsx.net/releases/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.plotSquaredCore)
|
||||
|
||||
// Metrics
|
||||
implementation("org.bstats:bstats-bukkit")
|
||||
|
||||
// Paper
|
||||
compileOnly("io.papermc.paper:paper-api")
|
||||
implementation("io.papermc:paperlib")
|
||||
|
||||
// Plugins
|
||||
compileOnly(libs.worldeditBukkit) {
|
||||
exclude(group = "org.bukkit")
|
||||
exclude(group = "org.spigotmc")
|
||||
}
|
||||
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") { isTransitive = false }
|
||||
testImplementation("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") { isTransitive = false }
|
||||
compileOnly("com.github.MilkBowl:VaultAPI") {
|
||||
exclude(group = "org.bukkit")
|
||||
}
|
||||
compileOnly(libs.placeholderapi)
|
||||
compileOnly(libs.luckperms)
|
||||
compileOnly(libs.essentialsx)
|
||||
compileOnly(libs.mvdwapi) { isTransitive = false }
|
||||
|
||||
// Other libraries
|
||||
implementation(libs.squirrelid) { isTransitive = false }
|
||||
implementation("dev.notmyfault.serverlib:ServerLib")
|
||||
|
||||
// Our libraries
|
||||
implementation(libs.arkitektonika)
|
||||
implementation(libs.http4j)
|
||||
implementation("com.intellectualsites.paster:Paster")
|
||||
implementation("com.intellectualsites.informative-annotations:informative-annotations")
|
||||
|
||||
// Adventure
|
||||
implementation("net.kyori:adventure-platform-bukkit")
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching("plugin.yml") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
dependencies {
|
||||
exclude(dependency("org.checkerframework:"))
|
||||
}
|
||||
|
||||
relocate("net.kyori.adventure", "com.plotsquared.core.configuration.adventure")
|
||||
relocate("net.kyori.examination", "com.plotsquared.core.configuration.examination")
|
||||
relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
|
||||
relocate("org.bstats", "com.plotsquared.metrics")
|
||||
relocate("org.enginehub", "com.plotsquared.squirrelid")
|
||||
relocate("org.khelekore.prtree", "com.plotsquared.prtree")
|
||||
relocate("com.google.inject", "com.plotsquared.google")
|
||||
relocate("org.aopalliance", "com.plotsquared.core.aopalliance")
|
||||
relocate("cloud.commandframework.services", "com.plotsquared.core.services")
|
||||
relocate("io.leangen.geantyref", "com.plotsquared.core.geantyref")
|
||||
relocate("com.intellectualsites.arkitektonika", "com.plotsquared.core.arkitektonika")
|
||||
relocate("com.intellectualsites.http", "com.plotsquared.core.http")
|
||||
relocate("com.intellectualsites.paster", "com.plotsquared.core.paster")
|
||||
relocate("org.incendo.serverlib", "com.plotsquared.bukkit.serverlib")
|
||||
relocate("org.jetbrains", "com.plotsquared.core.annotations")
|
||||
relocate("org.intellij.lang", "com.plotsquared.core.intellij.annotations")
|
||||
relocate("javax.annotation", "com.plotsquared.core.annotation")
|
||||
relocate("com.github.spotbugs", "com.plotsquared.core.spotbugs")
|
||||
relocate("javax.inject", "com.plotsquared.core.annotation.inject")
|
||||
relocate("net.jcip", "com.plotsquared.core.annotations.jcip")
|
||||
relocate("edu.umd.cs.findbugs", "com.plotsquared.core.annotations.findbugs")
|
||||
relocate("com.intellectualsites.informative-annotations", "com.plotsquared.core.annotation.informative")
|
||||
|
||||
// Get rid of all the libs which are 100% unused.
|
||||
minimize()
|
||||
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<Javadoc> {
|
||||
val isRelease = if (rootProject.version.toString().endsWith("-SNAPSHOT")) "TODO" else rootProject.version.toString()
|
||||
val opt = options as StandardJavadocDocletOptions
|
||||
opt.links("https://jd.papermc.io/paper/1.18/")
|
||||
opt.links("https://docs.enginehub.org/javadoc/com.sk89q.worldedit/worldedit-bukkit/" + libs.worldeditBukkit.get().versionConstraint.toString())
|
||||
opt.links("https://intellectualsites.github.io/plotsquared-javadocs/core/")
|
||||
opt.links("https://jd.adventure.kyori.net/api/4.9.3/")
|
||||
opt.links("https://google.github.io/guice/api-docs/" + libs.guice.get().versionConstraint.toString() + "/javadoc/")
|
||||
opt.links("https://checkerframework.org/api/")
|
||||
opt.isLinkSource = true
|
||||
opt.bottom(File("$rootDir/javadocfooter.html").readText())
|
||||
opt.isUse = true
|
||||
opt.encoding("UTF-8")
|
||||
opt.keyWords()
|
||||
opt.addStringOption("-since", isRelease)
|
||||
}
|
||||
}
|
@ -0,0 +1,758 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.intellectualcrafters.plot.api;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* PlotSquared API
|
||||
*
|
||||
|
||||
|
||||
* @version API 2.0
|
||||
*
|
||||
*/
|
||||
|
||||
public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Permission that allows for admin access, this permission node will allow the player to use any part of the
|
||||
* plugin, without limitations.
|
||||
* @deprecated Use C.PERMISSION_ADMIN.s() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
|
||||
|
||||
/**
|
||||
* @deprecated Use new PlotAPI() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI(final JavaPlugin plugin) {}
|
||||
|
||||
/**
|
||||
* @see PS
|
||||
*
|
||||
* @deprecated Use this class if you just want to do a few simple things.<br>
|
||||
* - It will remain stable for future versions of the plugin
|
||||
* - The PlotPlayer and Plot class should be considered relatively safe
|
||||
* - For more advanced/intensive tasks you should consider using other classes
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI() {}
|
||||
|
||||
/**
|
||||
* Get all plots
|
||||
*
|
||||
* @return all plots
|
||||
*
|
||||
* @see PS#getPlots()
|
||||
*/
|
||||
public Set<Plot> getAllPlots() {
|
||||
return PS.get().getPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all plots for a player
|
||||
*
|
||||
* @param player Player, whose plots to search for
|
||||
*
|
||||
* @return all plots that a player owns
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final Player player) {
|
||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plot world
|
||||
*
|
||||
* @param plotArea Plot World Object
|
||||
* @see PS#addPlotArea(PlotArea)
|
||||
*/
|
||||
public void addPlotArea(final PlotArea plotArea) {
|
||||
PS.get().addPlotArea(plotArea);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return main configuration
|
||||
*
|
||||
* @see PS#config
|
||||
*/
|
||||
public YamlConfiguration getConfig() {
|
||||
return PS.get().config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return storage configuration
|
||||
*
|
||||
* @see PS#storage
|
||||
*/
|
||||
public YamlConfiguration getStorage() {
|
||||
return PS.get().storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main class for this plugin <br> - Contains a lot of fields and methods - not very well organized <br>
|
||||
* Only use this if you really need it
|
||||
*
|
||||
* @return PlotSquared PlotSquared Main Class
|
||||
*
|
||||
* @see PS
|
||||
*/
|
||||
public PS getMain() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* ChunkManager class contains several useful methods<br>
|
||||
* - Chunk deletion<br>
|
||||
* - Moving or copying regions<br>
|
||||
* - plot swapping<br>
|
||||
* - Entity tracking<br>
|
||||
* - region regeneration<br>
|
||||
*
|
||||
* @return ChunkManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.ChunkManager
|
||||
*/
|
||||
public ChunkManager getChunkManager() {
|
||||
return ChunkManager.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block/biome set queue
|
||||
* @return SetQueue.IMP
|
||||
*/
|
||||
public SetQueue getSetQueue() {
|
||||
return SetQueue.IMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead)
|
||||
*
|
||||
* @return UUIDWrapper
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.uuid.UUIDWrapper
|
||||
*/
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
return UUIDHandler.getUUIDWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use FlagManager.[method] in your code.
|
||||
* - Flag related stuff
|
||||
*
|
||||
* @return FlagManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager
|
||||
*/
|
||||
@Deprecated
|
||||
public FlagManager getFlagManager() {
|
||||
return new FlagManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use MainUtil.[method] in your code.
|
||||
* - Basic plot management stuff
|
||||
*
|
||||
* @return MainUtil
|
||||
*
|
||||
* @see MainUtil
|
||||
*/
|
||||
@Deprecated
|
||||
public MainUtil getMainUtil() {
|
||||
return new MainUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this. Instead use C.PERMISSION_[method] in your code.
|
||||
* - Basic permission management stuff
|
||||
*
|
||||
* @return Array of strings
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.Permissions
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getPermissions() {
|
||||
final ArrayList<String> perms = new ArrayList<>();
|
||||
for (final C c : C.values()) {
|
||||
if ("static.permissions".equals(c.getCat())) {
|
||||
perms.add(c.s());
|
||||
}
|
||||
}
|
||||
return perms.toArray(new String[perms.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* SchematicHandler class contains methods related to pasting, reading and writing schematics
|
||||
*
|
||||
* @return SchematicHandler
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.SchematicHandler
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
return SchematicHandler.manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use C.[caption] instead
|
||||
*
|
||||
* @return C
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
@Deprecated
|
||||
public C[] getCaptions() {
|
||||
return C.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil
|
||||
*
|
||||
* @param world Which manager to get
|
||||
*
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
* @see PS#getPlotManager(Plot)
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotManager getPlotManager(final World world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
return getPlotManager(world.getName());
|
||||
}
|
||||
|
||||
public Set<PlotArea> getPlotAreas(World world) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return PS.get().getPlotAreas(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and
|
||||
* tessellation
|
||||
*
|
||||
* @param world
|
||||
*
|
||||
* @return PlotManager
|
||||
*
|
||||
* @see PS#getPlotManager(Plot)
|
||||
* @see com.intellectualcrafters.plot.object.PlotManager
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotManager getPlotManager(final String world) {
|
||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
||||
switch (areas.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return areas.iterator().next().manager;
|
||||
default:
|
||||
PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific
|
||||
* settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea
|
||||
*
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotArea class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @see #getPlotAreas(World)
|
||||
* @see com.intellectualcrafters.plot.object.PlotArea
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotArea getWorldSettings(final World world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
return getWorldSettings(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotArea class)
|
||||
*
|
||||
* @param world (to get settings of)
|
||||
*
|
||||
* @return PlotArea class for that world ! will return null if not a plot world world
|
||||
*
|
||||
* @see PS#getPlotArea(String, String)
|
||||
* @see com.intellectualcrafters.plot.object.PlotArea
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotArea getWorldSettings(final String world) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
||||
switch (areas.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return areas.iterator().next();
|
||||
default:
|
||||
PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
* @param player Player that will receive the message
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
* com.intellectualcrafters.plot.config.C, String...)
|
||||
*/
|
||||
public void sendMessage(final Player player, final C c) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player. - Supports color codes
|
||||
*
|
||||
* @param player Player that will receive the message
|
||||
* @param string The message
|
||||
*
|
||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||
*/
|
||||
public void sendMessage(final Player player, final String string) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console. - Supports color codes
|
||||
*
|
||||
* @param msg Message that should be sent to the console
|
||||
*
|
||||
* @see MainUtil#sendConsoleMessage(C, String...)
|
||||
*/
|
||||
public void sendConsoleMessage(final String msg) {
|
||||
PS.log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the console
|
||||
*
|
||||
* @param c (Caption)
|
||||
*
|
||||
* @see #sendConsoleMessage(String)
|
||||
* @see com.intellectualcrafters.plot.config.C
|
||||
*/
|
||||
public void sendConsoleMessage(final C c) {
|
||||
sendConsoleMessage(c.s());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a flag for use in plots
|
||||
*
|
||||
* @param flag Flag that should be registered
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag)
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
public void addFlag(final AbstractFlag flag) {
|
||||
FlagManager.addFlag(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the currently registered flags
|
||||
*
|
||||
* @return array of Flag[]
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.flag.FlagManager#getFlags()
|
||||
* @see com.intellectualcrafters.plot.flag.AbstractFlag
|
||||
*/
|
||||
public AbstractFlag[] getFlags() {
|
||||
return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the ID
|
||||
*
|
||||
* @param world World in which the plot is located
|
||||
* @param x Plot Location X Co-ord
|
||||
* @param z Plot Location Z Co-ord
|
||||
*
|
||||
* @return plot, null if ID is wrong
|
||||
*
|
||||
* @see PlotArea#getPlot(PlotId)
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot getPlot(final World world, final int x, final int z) {
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
PlotArea area = getWorldSettings(world);
|
||||
if (area == null) {
|
||||
return null;
|
||||
}
|
||||
return area.getPlot(new PlotId(x, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the location
|
||||
*
|
||||
* @param l The location that you want to to retrieve the plot from
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot-
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(final Location l) {
|
||||
if (l == null) {
|
||||
return null;
|
||||
}
|
||||
return BukkitUtil.getLocation(l).getPlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot based on the player location
|
||||
*
|
||||
* @param player Get the current plot for the player location
|
||||
*
|
||||
* @return plot if found, otherwise it creates a temporary plot
|
||||
*
|
||||
* @see #getPlot(org.bukkit.Location)
|
||||
* @see Plot
|
||||
*/
|
||||
public Plot getPlot(final Player player) {
|
||||
return this.getPlot(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player has a plot
|
||||
*
|
||||
* @param player Player that you want to check for
|
||||
*
|
||||
* @return true if player has a plot, false if not.
|
||||
*
|
||||
* @see #getPlots(World, Player, boolean)
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasPlot(final World world, final Player player) {
|
||||
return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the player
|
||||
*
|
||||
* @param plr to search for
|
||||
* @param just_owner should we just search for owner? Or with rights?
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) {
|
||||
final ArrayList<Plot> pPlots = new ArrayList<>();
|
||||
UUID uuid = BukkitUtil.getPlayer(plr).getUUID();
|
||||
for (final Plot plot : PS.get().getPlots(world.getName())) {
|
||||
if (just_owner) {
|
||||
if (plot.hasOwner() && plot.isOwner(uuid)) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
} else {
|
||||
if (plot.isAdded(uuid)) {
|
||||
pPlots.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pPlots.toArray(new Plot[pPlots.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots for the world
|
||||
*
|
||||
* @param world to get plots of
|
||||
*
|
||||
* @return Plot[] - array of plot objects in world
|
||||
*
|
||||
* @see PS#getPlots(String)
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Plot[] getPlots(final World world) {
|
||||
if (world == null) {
|
||||
return new Plot[0];
|
||||
}
|
||||
Collection<Plot> plots = PS.get().getPlots(world.getName());
|
||||
return plots.toArray(new Plot[plots.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plot worlds
|
||||
*
|
||||
* @return World[] - array of plot worlds
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getPlotWorlds() {
|
||||
Set<String> plotWorldStrings = PS.get().getPlotWorldStrings();
|
||||
return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if plot world
|
||||
*
|
||||
* @param world (to check if plot world)
|
||||
*
|
||||
* @return boolean (if plot world or not)
|
||||
*
|
||||
* @see PS#hasPlotArea(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isPlotWorld(final World world) {
|
||||
return PS.get().hasPlotArea(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plot locations
|
||||
*
|
||||
* @param p Plot that you want to get the locations for
|
||||
*
|
||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
||||
*
|
||||
* @deprecated As merged plots may not have a rectangular shape
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location[] getLocations(final Plot p) {
|
||||
return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get home location
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Location getHomeLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(p.getHome());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bottom Location (min, min, min)
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot bottom location
|
||||
*
|
||||
* @deprecated As merged plots may not have a rectangular shape
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getBottomLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(p.getBottom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Top Location (max, max, max)
|
||||
*
|
||||
* @param p Plot that you want to get the location for
|
||||
*
|
||||
* @return plot top location
|
||||
*
|
||||
* @deprecated As merged plots may not have a rectangular shape
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getTopLocation(final Plot p) {
|
||||
return BukkitUtil.getLocation(p.getTop());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a player is in a plot
|
||||
*
|
||||
* @param player who we're checking for
|
||||
*
|
||||
* @return true if the player is in a plot, false if not-
|
||||
*
|
||||
*/
|
||||
public boolean isInPlot(final Player player) {
|
||||
return getPlot(player) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a subcommand
|
||||
*
|
||||
* @param c SubCommand, that we want to register
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.SubCommand
|
||||
*/
|
||||
public void registerCommand(final SubCommand c) {
|
||||
if (c.getCommand() != null) {
|
||||
MainCommand.getInstance().addCommand(c);
|
||||
} else {
|
||||
MainCommand.getInstance().createCommand(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotSquared class
|
||||
*
|
||||
* @return PlotSquared Class
|
||||
*
|
||||
* @see PS
|
||||
*/
|
||||
public PS getPlotSquared() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player plot count
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plot count
|
||||
*
|
||||
* @return the number of plots the player has
|
||||
*
|
||||
*/
|
||||
public int getPlayerPlotCount(final World world, final Player player) {
|
||||
if (world == null) {
|
||||
return 0;
|
||||
}
|
||||
return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection containing the players plots
|
||||
*
|
||||
* @param world Specify the world we want to select the plots from
|
||||
* @param player Player, for whom we're getting the plots
|
||||
*
|
||||
* @return a set containing the players plots
|
||||
*
|
||||
* @see PS#getPlots(String, PlotPlayer)
|
||||
*
|
||||
* @see Plot
|
||||
*/
|
||||
public Set<Plot> getPlayerPlots(final World world, final Player player) {
|
||||
if (world == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return BukkitUtil.getPlayer(player).getPlots(world.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the numbers of plots, which the player is able to build in
|
||||
*
|
||||
* @param player Player, for whom we're getting the plots (trusted, member and owner)
|
||||
*
|
||||
* @return the number of allowed plots
|
||||
*
|
||||
*/
|
||||
public int getAllowedPlots(final Player player) {
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
return pp.getAllowedPlots();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for a player<br>
|
||||
* - The PlotPlayer is usually cached and will provide useful functions relating to players
|
||||
*
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final Player player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit)
|
||||
*
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final UUID uuid) {
|
||||
return PlotPlayer.wrap(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for a username
|
||||
*
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final String player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotPlayer for an offline player<br>
|
||||
* Note that this will work if the player is offline, however not all functionality will work
|
||||
*
|
||||
* @see PlotPlayer#wrap(Object)
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public PlotPlayer wrapPlayer(final OfflinePlayer player) {
|
||||
return PlotPlayer.wrap(player);
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.command.MainCommand;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.ProxiedCommandSender;
|
||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
CommandSender commandSender, Command command, String commandLabel,
|
||||
String[] args
|
||||
) {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.adapt((Player) commandSender), args);
|
||||
}
|
||||
if (commandSender instanceof ConsoleCommandSender
|
||||
|| commandSender instanceof ProxiedCommandSender
|
||||
|| commandSender instanceof RemoteConsoleCommandSender) {
|
||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
CommandSender commandSender, Command command, String label,
|
||||
String[] args
|
||||
) {
|
||||
if (!(commandSender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
PlotPlayer<?> player = BukkitUtil.adapt((Player) commandSender);
|
||||
if (args.length == 0) {
|
||||
return Collections.singletonList("plots");
|
||||
}
|
||||
if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES.contains(label.toLowerCase(Locale.ENGLISH))) {
|
||||
return List.of();
|
||||
}
|
||||
Collection<com.plotsquared.core.command.Command> objects =
|
||||
MainCommand.getInstance().tab(player, args, label.endsWith(" "));
|
||||
if (objects == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
for (com.plotsquared.core.command.Command o : objects) {
|
||||
result.add(o.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
645
Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
Normal file
645
Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
Normal file
@ -0,0 +1,645 @@
|
||||
package com.plotsquared.bukkit;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.plot.IPlotMain;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.bukkit.commands.DebugUUID;
|
||||
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
||||
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
||||
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.plotsquared.bukkit.listeners.*;
|
||||
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
|
||||
import com.plotsquared.bukkit.titles.DefaultTitle;
|
||||
import com.plotsquared.bukkit.util.*;
|
||||
import com.plotsquared.bukkit.util.block.FastQueue_1_7;
|
||||
import com.plotsquared.bukkit.util.block.FastQueue_1_8;
|
||||
import com.plotsquared.bukkit.util.block.FastQueue_1_8_3;
|
||||
import com.plotsquared.bukkit.util.block.SlowQueue;
|
||||
import com.plotsquared.bukkit.uuid.*;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
public static BukkitMain THIS;
|
||||
public static WorldEditPlugin worldEdit;
|
||||
|
||||
private int[] version;
|
||||
|
||||
@Override
|
||||
public int[] getServerVersion() {
|
||||
if (version == null) {
|
||||
try {
|
||||
version = new int[3];
|
||||
final String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
||||
version[0] = Integer.parseInt(split[0]);
|
||||
version[1] = Integer.parseInt(split[1]);
|
||||
if (split.length == 3) {
|
||||
version[2] = Integer.parseInt(split[2]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
PS.debug(StringMan.getString(Bukkit.getBukkitVersion()));
|
||||
PS.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
|
||||
return new int[]{Integer.MAX_VALUE, 0, 0};
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
THIS = this;
|
||||
new PS(this, "Bukkit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PS.get().disable();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
if ((THIS != null) && (Bukkit.getServer().getConsoleSender() != null)) {
|
||||
try {
|
||||
message = C.color(message);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
return;
|
||||
} catch (final Throwable e) {}
|
||||
}
|
||||
System.out.println(ConsoleColors.fromString(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (THIS != null) {
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
final String[] split = getDescription().getVersion().split("\\.");
|
||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands() {
|
||||
final BukkitCommand bcmd = new BukkitCommand();
|
||||
final PluginCommand plotCommand = getCommand("plots");
|
||||
plotCommand.setExecutor(bcmd);
|
||||
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||
plotCommand.setTabCompleter(bcmd);
|
||||
MainCommand.getInstance().addCommand(new DebugUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDirectory() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldContainer() {
|
||||
return Bukkit.getWorldContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
return new BukkitTaskManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runEntityTask() {
|
||||
log(C.PREFIX.s() + "KillAllEntities started.");
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@Override
|
||||
public void run(PlotArea pw) {
|
||||
World world = Bukkit.getWorld(pw.worldname);
|
||||
try {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
List<Entity> entities = world.getEntities();
|
||||
Iterator<Entity> iter = entities.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entity entity = iter.next();
|
||||
switch (entity.getType()) {
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case COMPLEX_PART:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case WEATHER:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case PLAYER: {
|
||||
// non moving / unremovable
|
||||
continue;
|
||||
}
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPLASH_POTION:
|
||||
case SNOWBALL:
|
||||
case ENDER_PEARL:
|
||||
case ARROW: {
|
||||
// managed elsewhere | projectile
|
||||
continue;
|
||||
}
|
||||
case ARMOR_STAND:
|
||||
case ITEM_FRAME:
|
||||
case PAINTING: {
|
||||
// TEMPORARILY CLASSIFY AS VEHICLE
|
||||
}
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
case BOAT: {
|
||||
if (!Settings.KILL_ROAD_VEHICLES) {
|
||||
continue;
|
||||
}
|
||||
com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(entity.getLocation());
|
||||
Plot plot = loc.getPlot();
|
||||
if (plot == null) {
|
||||
if (loc.isPlotArea()) {
|
||||
iter.remove();
|
||||
entity.remove();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (!plot.equals(origin.getBasePlot(false))) {
|
||||
iter.remove();
|
||||
entity.remove();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
case DROPPED_ITEM: {
|
||||
// dropped item
|
||||
continue;
|
||||
}
|
||||
case PRIMED_TNT:
|
||||
case FALLING_BLOCK: {
|
||||
// managed elsewhere
|
||||
continue;
|
||||
}
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case CREEPER:
|
||||
case ENDERMAN:
|
||||
case ENDERMITE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case GUARDIAN:
|
||||
case HORSE:
|
||||
case IRON_GOLEM:
|
||||
case MAGMA_CUBE:
|
||||
case MUSHROOM_COW:
|
||||
case OCELOT:
|
||||
case PIG:
|
||||
case PIG_ZOMBIE:
|
||||
case RABBIT:
|
||||
case SHEEP:
|
||||
case SILVERFISH:
|
||||
case SKELETON:
|
||||
case SLIME:
|
||||
case SNOWMAN:
|
||||
case SPIDER:
|
||||
case SQUID:
|
||||
case VILLAGER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case WOLF:
|
||||
case ZOMBIE:
|
||||
default: {
|
||||
if (!Settings.KILL_ROAD_MOBS) {
|
||||
continue;
|
||||
}
|
||||
final Location loc = entity.getLocation();
|
||||
if (BukkitUtil.getLocation(loc).isPlotRoad()) {
|
||||
final Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player)) {
|
||||
if (entity.getMetadata("keep").isEmpty()) {
|
||||
iter.remove();
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
||||
final HybridGen result = new HybridGen();
|
||||
if (!PS.get().setupPlotWorld(world, id, result)) {
|
||||
return null;
|
||||
}
|
||||
return (ChunkGenerator) result.specify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
||||
}
|
||||
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInventoryEvents() {
|
||||
// Part of PlayerEvents - can be moved if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlotPlusEvents() {
|
||||
PlotPlusListener.startRunnable(this);
|
||||
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerForceFieldEvents() {
|
||||
getServer().getPluginManager().registerEvents(new ForceFieldListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initWorldEdit() {
|
||||
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||
BukkitMain.worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
final String version = BukkitMain.worldEdit.getDescription().getVersion();
|
||||
if ((version != null) && version.startsWith("5.")) {
|
||||
log("&cThis version of WorldEdit does not support PlotSquared.");
|
||||
log("&cPlease use WorldEdit 6+ for masking support");
|
||||
log("&c - http://builds.enginehub.org/job/worldedit");
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new WEListener(), this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EconHandler getEconomyHandler() {
|
||||
try {
|
||||
final BukkitEconHandler econ = new BukkitEconHandler();
|
||||
if (econ.init()) {
|
||||
return econ;
|
||||
}
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotQueue initPlotQueue() {
|
||||
try {
|
||||
new SendChunk();
|
||||
MainUtil.canSendChunk = true;
|
||||
} catch (final Throwable e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) {
|
||||
try {
|
||||
return new FastQueue_1_8_3();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
return new FastQueue_1_8();
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
return new SlowQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
return new FastQueue_1_7();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return new SlowQueue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldUtil initWorldUtil() {
|
||||
return new BukkitUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initPlotMeConverter() {
|
||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
|
||||
return;
|
||||
}
|
||||
if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
|
||||
return;
|
||||
}
|
||||
if (new LikePlotMeConverter("AthionPlots").run(new ClassicPlotMeConnector())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
return (Bukkit.getPluginManager().getPlugin("PlotMe") != null) || (Bukkit.getPluginManager().getPlugin("AthionPlots") != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorWrapper<?> getGenerator(final String world, final String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
||||
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||
ChunkGenerator gen = gen_plugin.getDefaultWorldGenerator(world, "");
|
||||
if (gen instanceof GeneratorWrapper<?>) {
|
||||
return (GeneratorWrapper<?>) gen;
|
||||
}
|
||||
return new BukkitPlotGenerator(world, gen);
|
||||
} else {
|
||||
return new BukkitPlotGenerator(new HybridGen());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HybridUtils initHybridUtils() {
|
||||
return new BukkitHybridUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetupUtils initSetupUtils() {
|
||||
return new BukkitSetupUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUIDHandlerImplementation initUUIDHandler() {
|
||||
final boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
|
||||
UUIDWrapper wrapper;
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
if (Settings.UUID_LOWERCASE) {
|
||||
wrapper = (new LowerOfflineUUIDWrapper());
|
||||
} else {
|
||||
wrapper = (new OfflineUUIDWrapper());
|
||||
}
|
||||
Settings.OFFLINE_MODE = true;
|
||||
} else if (checkVersion) {
|
||||
wrapper = (new DefaultUUIDWrapper());
|
||||
Settings.OFFLINE_MODE = false;
|
||||
} else {
|
||||
if (Settings.UUID_LOWERCASE) {
|
||||
wrapper = (new LowerOfflineUUIDWrapper());
|
||||
} else {
|
||||
wrapper = (new OfflineUUIDWrapper());
|
||||
}
|
||||
Settings.OFFLINE_MODE = true;
|
||||
}
|
||||
if (!checkVersion) {
|
||||
log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
FlagManager.removeFlag(FlagManager.getFlag("titles"));
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle();
|
||||
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||
Settings.TWIN_MODE_UUID = true;
|
||||
}
|
||||
}
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
|
||||
} else {
|
||||
log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs");
|
||||
}
|
||||
return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkManager initChunkManager() {
|
||||
return new BukkitChunkManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventUtil initEventUtil() {
|
||||
return new BukkitEventUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(final PlotPlayer player) {
|
||||
BukkitUtil.removePlayer(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerChunkProcessor() {
|
||||
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWorldEvents() {
|
||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryUtil initInventoryUtil() {
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return Bukkit.getServerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (IOException e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(final String worldname) {
|
||||
World world = BukkitUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
// create world
|
||||
final ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
|
||||
String manager = worldConfig.getString("generator.plugin");
|
||||
if (manager == null) {
|
||||
manager = "PlotSquared";
|
||||
}
|
||||
String generator = worldConfig.getString("generator.init");
|
||||
if (generator == null) {
|
||||
generator = manager;
|
||||
}
|
||||
|
||||
final int type = worldConfig.getInt("generator.type");
|
||||
final int terrain = worldConfig.getInt("generator.terrain");
|
||||
final SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = generator;
|
||||
setup.type = type;
|
||||
setup.terrain = terrain;
|
||||
setup.step = new ConfigurationNode[0];
|
||||
setup.world = worldname;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
} else {
|
||||
try {
|
||||
if (!PS.get().hasPlotArea(worldname)) {
|
||||
SetGenCB.setGenerator(BukkitUtil.getWorld(worldname));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log("Failed to reload world: " + world);
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
}
|
||||
}
|
||||
world = Bukkit.getWorld(worldname);
|
||||
final ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof BukkitPlotGenerator) {
|
||||
PS.get().loadWorld(worldname, (BukkitPlotGenerator) gen);
|
||||
} else if (gen != null) {
|
||||
PS.get().loadWorld(worldname, new BukkitPlotGenerator(worldname, gen));
|
||||
} else {
|
||||
if (PS.get().config.contains("worlds." + worldname)) {
|
||||
PS.get().loadWorld(worldname, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicHandler initSchematicHandler() {
|
||||
return new BukkitSchematicHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTitle initTitleManager() {
|
||||
// Already initialized in UUID handler
|
||||
return AbstractTitle.TITLE_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotPlayer wrapPlayer(final Object obj) {
|
||||
if (obj instanceof Player) {
|
||||
return BukkitUtil.getPlayer((Player) obj);
|
||||
} else if (obj instanceof OfflinePlayer) {
|
||||
return BukkitUtil.getPlayer((OfflinePlayer) obj);
|
||||
} else if (obj instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) obj);
|
||||
} else if (obj instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) obj);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNMSPackage() {
|
||||
final Server server = Bukkit.getServer();
|
||||
final Class<?> bukkitServerClass = server.getClass();
|
||||
String[] pas = bukkitServerClass.getName().split("\\.");
|
||||
if (pas.length == 5) {
|
||||
return pas[3];
|
||||
}
|
||||
try {
|
||||
final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle");
|
||||
final Object handle = getHandle.invoke(server);
|
||||
final Class handleServerClass = handle.getClass();
|
||||
pas = handleServerClass.getName().split("\\.");
|
||||
if (pas.length == 5) {
|
||||
return pas[3];
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException | SecurityException | NoSuchMethodException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PS.debug("Unknown NMS package: " + StringMan.getString(pas));
|
||||
return "1_8_R3";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatManager<?> initChatManager() {
|
||||
if (Settings.FANCY_CHAT) {
|
||||
return new BukkitChatManager();
|
||||
} else {
|
||||
return new BukkitPlainChatManager();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator) {
|
||||
return new BukkitPlotGenerator(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPluginIds() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
names.add(plugin.getName() + ";" + plugin.getDescription().getVersion() + ":" + plugin.isEnabled());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,103 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
/**
|
||||
* Represents a wrapper around an array class of an arbitrary reference type,
|
||||
* which properly implements "value" hash code and equality functions.
|
||||
* <p>
|
||||
* This class is intended for use as a key to a map.
|
||||
* </p>
|
||||
* @author Glen Husman
|
||||
* @param <E> The type of elements in the array.
|
||||
* @see Arrays
|
||||
*/
|
||||
public final class ArrayWrapper<E> {
|
||||
|
||||
/**
|
||||
* Creates an array wrapper with some elements.
|
||||
* @param elements The elements of the array.
|
||||
*/
|
||||
public ArrayWrapper(final E... elements) {
|
||||
setArray(elements);
|
||||
}
|
||||
|
||||
private E[] _array;
|
||||
|
||||
/**
|
||||
* Retrieves a reference to the wrapped array instance.
|
||||
* @return The array wrapped by this instance.
|
||||
*/
|
||||
public E[] getArray() {
|
||||
return _array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this wrapper to wrap a new array instance.
|
||||
* @param array The new wrapped array.
|
||||
*/
|
||||
public void setArray(final E[] array) {
|
||||
Validate.notNull(array, "The array must not be null.");
|
||||
_array = array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this object has a value equivalent to another object.
|
||||
* @see Arrays#equals(Object[], Object[])
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (!(other instanceof ArrayWrapper)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(_array, ((ArrayWrapper) other)._array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hash code represented by this objects value.
|
||||
* @see Arrays#hashCode(Object[])
|
||||
* @return This object's hash code.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an iterable element collection to an array of elements.
|
||||
* The iteration order of the specified object will be used as the array element order.
|
||||
* @param list The iterable of objects which will be converted to an array.
|
||||
* @param c The type of the elements of the array.
|
||||
* @return An array of elements in the specified iterable.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] toArray(final Iterable<? extends T> list, final Class<T> c) {
|
||||
int size = -1;
|
||||
if (list instanceof Collection<?>) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final Collection coll = (Collection) list;
|
||||
size = coll.size();
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
size = 0;
|
||||
// Ugly hack: Count it ourselves
|
||||
for (@SuppressWarnings("unused")
|
||||
final T element : list) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
final T[] result = (T[]) Array.newInstance(c, size);
|
||||
int i = 0;
|
||||
for (final T element : list) { // Assumes iteration order is consistent
|
||||
result[i++] = element; // Assign array element at index THEN increment counter
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,847 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.Achievement;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.Statistic.Type;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
|
||||
* This class allows plugins to emulate the functionality of the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Commands#tellraw">tellraw command</a>.
|
||||
* <p>
|
||||
* This class follows the builder pattern, allowing for method chaining.
|
||||
* It is set up such that invocations of property-setting methods will affect the current editing component,
|
||||
* and a call to {@link #then(String)} or {@link #text(TextualComponent)} will append a new editing component to the end of the message,
|
||||
* optionally initializing it with text. Further property-setting method calls will affect that editing component.
|
||||
* </p>
|
||||
*/
|
||||
public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<MessagePart>, ConfigurationSerializable {
|
||||
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(FancyMessage.class);
|
||||
}
|
||||
|
||||
private List<MessagePart> messageParts;
|
||||
private String jsonString;
|
||||
private boolean dirty;
|
||||
|
||||
private static Constructor<?> nmsPacketPlayOutChatConstructor;
|
||||
|
||||
@Override
|
||||
public FancyMessage clone() throws CloneNotSupportedException {
|
||||
final FancyMessage instance = (FancyMessage) super.clone();
|
||||
instance.messageParts = new ArrayList<>(messageParts.size());
|
||||
for (int i = 0; i < messageParts.size(); i++) {
|
||||
instance.messageParts.add(i, messageParts.get(i).clone());
|
||||
}
|
||||
instance.dirty = false;
|
||||
instance.jsonString = null;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSON message with text.
|
||||
* @param firstPartText The existing text in the message.
|
||||
*/
|
||||
public FancyMessage(final String firstPartText) {
|
||||
this(rawText(firstPartText));
|
||||
}
|
||||
|
||||
public FancyMessage(final TextualComponent firstPartText) {
|
||||
messageParts = new ArrayList<>();
|
||||
messageParts.add(new MessagePart(firstPartText));
|
||||
jsonString = null;
|
||||
dirty = false;
|
||||
|
||||
if (nmsPacketPlayOutChatConstructor == null) {
|
||||
try {
|
||||
nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
|
||||
nmsPacketPlayOutChatConstructor.setAccessible(true);
|
||||
} catch (final NoSuchMethodException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
|
||||
} catch (final SecurityException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSON message without text.
|
||||
*/
|
||||
public FancyMessage() {
|
||||
this((TextualComponent) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of the current editing component to a value.
|
||||
* @param text The new text of the current editing component.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage text(final String text) {
|
||||
final MessagePart latest = latest();
|
||||
latest.text = rawText(text);
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of the current editing component to a value.
|
||||
* @param text The new text of the current editing component.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage text(final TextualComponent text) {
|
||||
final MessagePart latest = latest();
|
||||
latest.text = text;
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the current editing component to a value.
|
||||
* @param color The new color of the current editing component.
|
||||
* @return This builder instance.
|
||||
* @exception IllegalArgumentException If the specified {@code ChatColor} enumeration value is not a color (but a format value).
|
||||
*/
|
||||
public FancyMessage color(final ChatColor color) {
|
||||
latest().color = color;
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stylization of the current editing component.
|
||||
* @param styles The array of styles to apply to the editing component.
|
||||
* @return This builder instance.
|
||||
* @exception IllegalArgumentException If any of the enumeration values in the array do not represent formatters.
|
||||
*/
|
||||
public FancyMessage style(final ChatColor... styles) {
|
||||
for (final ChatColor style : styles) {
|
||||
if (!style.isFormat()) {
|
||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||
}
|
||||
}
|
||||
latest().styles.addAll(Arrays.asList(styles));
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to instruct the client to open a file on the client side filesystem when the currently edited part of the {@code FancyMessage} is clicked.
|
||||
* @param path The path of the file on the client filesystem.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage file(final String path) {
|
||||
onClick("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to instruct the client to open a webpage in the client's web browser when the currently edited part of the {@code FancyMessage} is clicked.
|
||||
* @param url The URL of the page to open when the link is clicked.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage link(final String url) {
|
||||
onClick("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to instruct the client to replace the chat input box content with the specified string when the currently edited part of the {@code FancyMessage} is clicked.
|
||||
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.
|
||||
* @param command The text to display in the chat bar of the client.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage suggest(final String command) {
|
||||
onClick("suggest_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to instruct the client to append the chat input box content with the specified string when the currently edited part of the {@code FancyMessage} is SHIFT-CLICKED.
|
||||
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.
|
||||
* @param command The text to append to the chat bar of the client.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage insert(final String command) {
|
||||
latest().insertionData = command;
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to instruct the client to send the specified string to the server as a chat message when the currently edited part of the {@code FancyMessage} is clicked.
|
||||
* The client <b>will</b> immediately send the command to the server to be executed when the editing component is clicked.
|
||||
* @param command The text to display in the chat bar of the client.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage command(final String command) {
|
||||
onClick("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param name The name of the achievement to display, excluding the "achievement." prefix.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage achievementTooltip(final String name) {
|
||||
onHover("show_achievement", new JsonString("achievement." + name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param which The achievement to display.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage achievementTooltip(final Achievement which) {
|
||||
try {
|
||||
final Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
|
||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
|
||||
} catch (final IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
return this;
|
||||
} catch (final IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
return this;
|
||||
} catch (final InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about a parameterless statistic when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param which The statistic to display.
|
||||
* @return This builder instance.
|
||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied.
|
||||
*/
|
||||
public FancyMessage statisticTooltip(final Statistic which) {
|
||||
final Type type = which.getType();
|
||||
if (type != Type.UNTYPED) {
|
||||
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
|
||||
}
|
||||
try {
|
||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
|
||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||
} catch (final IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
return this;
|
||||
} catch (final IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
return this;
|
||||
} catch (final InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about a statistic parameter with a material when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param which The statistic to display.
|
||||
* @param item The sole material parameter to the statistic.
|
||||
* @return This builder instance.
|
||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
|
||||
*/
|
||||
public FancyMessage statisticTooltip(final Statistic which, final Material item) {
|
||||
final Type type = which.getType();
|
||||
if (type == Type.UNTYPED) {
|
||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||
}
|
||||
if (((type == Type.BLOCK) && item.isBlock()) || (type == Type.ENTITY)) {
|
||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
||||
}
|
||||
try {
|
||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
|
||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||
} catch (final IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
return this;
|
||||
} catch (final IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
return this;
|
||||
} catch (final InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about a statistic parameter with an entity type when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param which The statistic to display.
|
||||
* @param entity The sole entity type parameter to the statistic.
|
||||
* @return This builder instance.
|
||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
|
||||
*/
|
||||
public FancyMessage statisticTooltip(final Statistic which, final EntityType entity) {
|
||||
final Type type = which.getType();
|
||||
if (type == Type.UNTYPED) {
|
||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||
}
|
||||
if (type != Type.ENTITY) {
|
||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
||||
}
|
||||
try {
|
||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
|
||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||
} catch (final IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
return this;
|
||||
} catch (final IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
return this;
|
||||
} catch (final InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param itemJSON A string representing the JSON-serialized NBT data tag of an {@link ItemStack}.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage itemTooltip(final String itemJSON) {
|
||||
onHover("show_item", new JsonString(itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param itemStack The stack for which to display information.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
||||
try {
|
||||
final Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
||||
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound"))
|
||||
.invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param text The text, which supports newlines, which will be displayed to the client upon hovering.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage tooltip(final String text) {
|
||||
onHover("show_text", new JsonString(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage tooltip(final Iterable<String> lines) {
|
||||
tooltip(ArrayWrapper.toArray(lines, String.class));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param lines The lines of text which will be displayed to the client upon hovering.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage tooltip(final String... lines) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
builder.append(lines[i]);
|
||||
if (i != (lines.length - 1)) {
|
||||
builder.append('\n');
|
||||
}
|
||||
}
|
||||
tooltip(builder.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display formatted text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param text The formatted text which will be displayed to the client upon hovering.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage formattedTooltip(final FancyMessage text) {
|
||||
for (final MessagePart component : text.messageParts) {
|
||||
if ((component.clickActionData != null) && (component.clickActionName != null)) {
|
||||
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
||||
} else if ((component.hoverActionData != null) && (component.hoverActionName != null)) {
|
||||
throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
|
||||
}
|
||||
}
|
||||
onHover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param lines The lines of formatted text which will be displayed to the client upon hovering.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage formattedTooltip(final FancyMessage... lines) {
|
||||
if (lines.length < 1) {
|
||||
onHover(null, null); // Clear tooltip
|
||||
return this;
|
||||
}
|
||||
|
||||
final FancyMessage result = new FancyMessage();
|
||||
result.messageParts.clear(); // Remove the one existing text component that exists by default, which destabilizes the object
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
try {
|
||||
for (final MessagePart component : lines[i]) {
|
||||
if ((component.clickActionData != null) && (component.clickActionName != null)) {
|
||||
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
||||
} else if ((component.hoverActionData != null) && (component.hoverActionName != null)) {
|
||||
throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
|
||||
}
|
||||
if (component.hasText()) {
|
||||
result.messageParts.add(component.clone());
|
||||
}
|
||||
}
|
||||
if (i != (lines.length - 1)) {
|
||||
result.messageParts.add(new MessagePart(rawText("\n")));
|
||||
}
|
||||
} catch (final CloneNotSupportedException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to clone object", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return formattedTooltip(result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
||||
return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage translationReplacements(final String... replacements) {
|
||||
for (final String str : replacements) {
|
||||
latest().translationReplacements.add(new JsonString(str));
|
||||
}
|
||||
dirty = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||
* @return This builder instance.
|
||||
*//* ------------
|
||||
public FancyMessage translationReplacements(final Iterable<? extends CharSequence> replacements){
|
||||
for(CharSequence str : replacements){
|
||||
latest().translationReplacements.add(new JsonString(str));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage translationReplacements(final FancyMessage... replacements) {
|
||||
Collections.addAll(latest().translationReplacements, replacements);
|
||||
|
||||
dirty = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
||||
return translationReplacements(ArrayWrapper.toArray(replacements, FancyMessage.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
||||
* @param text The text which will populate the new message component.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage then(final String text) {
|
||||
return then(rawText(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
||||
* @param text The text which will populate the new message component.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage then(final TextualComponent text) {
|
||||
if (!latest().hasText()) {
|
||||
throw new IllegalStateException("previous message part has no text");
|
||||
}
|
||||
messageParts.add(new MessagePart(text));
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage then() {
|
||||
if (!latest().hasText()) {
|
||||
throw new IllegalStateException("previous message part has no text");
|
||||
}
|
||||
messageParts.add(new MessagePart());
|
||||
dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(final JsonWriter writer) throws IOException {
|
||||
if (messageParts.size() == 1) {
|
||||
latest().writeJson(writer);
|
||||
} else {
|
||||
writer.beginObject().name("text").value("").name("extra").beginArray();
|
||||
for (final MessagePart part : this) {
|
||||
part.writeJson(writer);
|
||||
}
|
||||
writer.endArray().endObject();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
|
||||
* This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
|
||||
* @return The JSON string representing this object.
|
||||
*/
|
||||
public String toJSONString() {
|
||||
if (!dirty && (jsonString != null)) {
|
||||
return jsonString;
|
||||
}
|
||||
final StringWriter string = new StringWriter();
|
||||
final JsonWriter json = new JsonWriter(string);
|
||||
try {
|
||||
writeJson(json);
|
||||
json.close();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("invalid message");
|
||||
}
|
||||
jsonString = string.toString();
|
||||
dirty = false;
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this message to a player. The player will receive the fully-fledged formatted display of this message.
|
||||
* @param player The player who will receive the message.
|
||||
*/
|
||||
public void send(final Player player) {
|
||||
send(player, toJSONString());
|
||||
}
|
||||
|
||||
private void send(final CommandSender sender, final String jsonString) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(toOldMessageFormat());
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) sender;
|
||||
try {
|
||||
final Object handle = Reflection.getHandle(player);
|
||||
final Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
} catch (final IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
} catch (final InstantiationException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
|
||||
} catch (final InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
} catch (final NoSuchMethodException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
|
||||
} catch (final ClassNotFoundException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not find class.", e);
|
||||
}
|
||||
}
|
||||
|
||||
// The ChatSerializer's instance of Gson
|
||||
private static Object nmsChatSerializerGsonInstance;
|
||||
private static Method fromJsonMethod;
|
||||
|
||||
private Object createChatPacket(final String json) throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException,
|
||||
ClassNotFoundException {
|
||||
if (nmsChatSerializerGsonInstance == null) {
|
||||
// Find the field and its value, completely bypassing obfuscation
|
||||
Class<?> chatSerializerClazz;
|
||||
|
||||
final String version = Reflection.getVersion();
|
||||
final double majorVersion = Double.parseDouble(version.replace('_', '.').substring(1, 4));
|
||||
final int lesserVersion = Integer.parseInt(version.substring(6, 7));
|
||||
|
||||
if ((majorVersion < 1.8) || ((majorVersion == 1.8) && (lesserVersion == 1))) {
|
||||
chatSerializerClazz = Reflection.getNMSClass("ChatSerializer");
|
||||
} else {
|
||||
chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
}
|
||||
|
||||
if (chatSerializerClazz == null) {
|
||||
throw new ClassNotFoundException("Can't find the ChatSerializer class");
|
||||
}
|
||||
|
||||
for (final Field declaredField : chatSerializerClazz.getDeclaredFields()) {
|
||||
if (Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType().getName().endsWith("Gson")) {
|
||||
// We've found our field
|
||||
declaredField.setAccessible(true);
|
||||
nmsChatSerializerGsonInstance = declaredField.get(null);
|
||||
fromJsonMethod = nmsChatSerializerGsonInstance.getClass().getMethod("fromJson", String.class, Class.class);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)'
|
||||
than to reflectively call it
|
||||
Of course, the implementation may change, but fuzzy matches might break with signature changes
|
||||
*/
|
||||
final Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent"));
|
||||
|
||||
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this message to a command sender.
|
||||
* If the sender is a player, they will receive the fully-fledged formatted display of this message.
|
||||
* Otherwise, they will receive a version of this message with less formatting.
|
||||
* @param sender The command sender who will receive the message.
|
||||
* @see #toOldMessageFormat()
|
||||
*/
|
||||
public void send(final CommandSender sender) {
|
||||
send(sender, toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this message to multiple command senders.
|
||||
* @param senders The command senders who will receive the message.
|
||||
* @see #send(CommandSender)
|
||||
*/
|
||||
public void send(final Iterable<? extends CommandSender> senders) {
|
||||
final String string = toJSONString();
|
||||
for (final CommandSender sender : senders) {
|
||||
send(sender, string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this message to a human-readable string with limited formatting.
|
||||
* This method is used to send this message to clients without JSON formatting support.
|
||||
* <p>
|
||||
* Serialization of this message by using this message will include (in this order for each message part):
|
||||
* <ol>
|
||||
* <li>The color of each message part.</li>
|
||||
* <li>The applicable stylization for each message part.</li>
|
||||
* <li>The core text of the message part.</li>
|
||||
* </ol>
|
||||
* The primary omissions are tooltips and clickable actions. Consequently, this method should be used only as a last resort.
|
||||
* </p>
|
||||
* <p>
|
||||
* Color and formatting can be removed from the returned string by using {@link ChatColor#stripColor(String)}.</p>
|
||||
* @return A human-readable string representing limited formatting in addition to the core text of this message.
|
||||
*/
|
||||
public String toOldMessageFormat() {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (final MessagePart part : this) {
|
||||
result.append(part.color == null ? "" : part.color);
|
||||
for (final ChatColor formatSpecifier : part.styles) {
|
||||
result.append(formatSpecifier);
|
||||
}
|
||||
result.append(part.text);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private MessagePart latest() {
|
||||
return messageParts.get(messageParts.size() - 1);
|
||||
}
|
||||
|
||||
private void onClick(final String name, final String data) {
|
||||
final MessagePart latest = latest();
|
||||
latest.clickActionName = name;
|
||||
latest.clickActionData = data;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
private void onHover(final String name, final JsonRepresentedObject data) {
|
||||
final MessagePart latest = latest();
|
||||
latest.hoverActionName = name;
|
||||
latest.hoverActionData = data;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
// Doc copied from interface
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("messageParts", messageParts);
|
||||
// map.put("JSON", toJSONString());
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON-represented message from a mapping of key-value pairs.
|
||||
* This is called by the Bukkit serialization API.
|
||||
* It is not intended for direct public API consumption.
|
||||
* @param serialized The key-value mapping which represents a fancy message.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static FancyMessage deserialize(final Map<String, Object> serialized) {
|
||||
final FancyMessage msg = new FancyMessage();
|
||||
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
||||
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
||||
msg.dirty = !serialized.containsKey("JSON");
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Internally called method. Not for API consumption.</b>
|
||||
*/
|
||||
@Override
|
||||
public Iterator<MessagePart> iterator() {
|
||||
return messageParts.iterator();
|
||||
}
|
||||
|
||||
private static JsonParser _stringParser = new JsonParser();
|
||||
|
||||
/**
|
||||
* Deserialize a fancy message from its JSON representation. This JSON representation is of the format of
|
||||
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
||||
* @param json The JSON string which represents a fancy message.
|
||||
* @return A {@code FancyMessage} representing the parametrized JSON message.
|
||||
*/
|
||||
public static FancyMessage deserialize(final String json) {
|
||||
final JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
||||
final JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
||||
final FancyMessage returnVal = new FancyMessage();
|
||||
returnVal.messageParts.clear();
|
||||
for (final JsonElement mPrt : extra) {
|
||||
final MessagePart component = new MessagePart();
|
||||
final JsonObject messagePart = mPrt.getAsJsonObject();
|
||||
for (final Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
||||
// Deserialize text
|
||||
if (TextualComponent.isTextKey(entry.getKey())) {
|
||||
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
||||
final Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
||||
serializedMapForm.put("key", entry.getKey());
|
||||
if (entry.getValue().isJsonPrimitive()) {
|
||||
// Assume string
|
||||
serializedMapForm.put("value", entry.getValue().getAsString());
|
||||
} else {
|
||||
// Composite object, but we assume each element is a string
|
||||
for (final Map.Entry<String, JsonElement> compositeNestedElement : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
|
||||
}
|
||||
}
|
||||
component.text = TextualComponent.deserialize(serializedMapForm);
|
||||
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
|
||||
if (entry.getValue().getAsBoolean()) {
|
||||
component.styles.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));
|
||||
}
|
||||
} else if (entry.getKey().equals("color")) {
|
||||
component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
||||
} else if (entry.getKey().equals("clickEvent")) {
|
||||
final JsonObject object = entry.getValue().getAsJsonObject();
|
||||
component.clickActionName = object.get("action").getAsString();
|
||||
component.clickActionData = object.get("value").getAsString();
|
||||
} else if (entry.getKey().equals("hoverEvent")) {
|
||||
final JsonObject object = entry.getValue().getAsJsonObject();
|
||||
component.hoverActionName = object.get("action").getAsString();
|
||||
if (object.get("value").isJsonPrimitive()) {
|
||||
// Assume string
|
||||
component.hoverActionData = new JsonString(object.get("value").getAsString());
|
||||
} else {
|
||||
// Assume composite type
|
||||
// The only composite type we currently store is another FancyMessage
|
||||
// Therefore, recursion time!
|
||||
component.hoverActionData = deserialize(object.get("value").toString() /* This should properly serialize the JSON object as a JSON string */);
|
||||
}
|
||||
} else if (entry.getKey().equals("insertion")) {
|
||||
component.insertionData = entry.getValue().getAsString();
|
||||
} else if (entry.getKey().equals("with")) {
|
||||
for (final JsonElement object : entry.getValue().getAsJsonArray()) {
|
||||
if (object.isJsonPrimitive()) {
|
||||
component.translationReplacements.add(new JsonString(object.getAsString()));
|
||||
} else {
|
||||
// Only composite type stored in this array is - again - FancyMessages
|
||||
// Recurse within this function to parse this as a translation replacement
|
||||
component.translationReplacements.add(deserialize(object.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
returnVal.messageParts.add(component);
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
/**
|
||||
* Represents an object that can be serialized to a JSON writer instance.
|
||||
*/
|
||||
interface JsonRepresentedObject {
|
||||
|
||||
/**
|
||||
* Writes the JSON representation of this object to the specified writer.
|
||||
* @param writer The JSON writer which will receive the object.
|
||||
* @throws IOException If an error occurs writing to the stream.
|
||||
*/
|
||||
void writeJson(final JsonWriter writer) throws IOException;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
/**
|
||||
* Represents a JSON string value.
|
||||
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
|
||||
* All writes merely write the represented string value.
|
||||
*/
|
||||
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
||||
|
||||
private final String _value;
|
||||
|
||||
public JsonString(final CharSequence value) {
|
||||
_value = value == null ? null : value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(final JsonWriter writer) throws IOException {
|
||||
writer.value(getValue());
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
final HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
|
||||
theSingleValue.put("stringValue", _value);
|
||||
return theSingleValue;
|
||||
}
|
||||
|
||||
public static JsonString deserialize(final Map<String, Object> map) {
|
||||
return new JsonString(map.get("stringValue").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _value;
|
||||
}
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Internal class: Represents a component of a JSON-serializable {@link FancyMessage}.
|
||||
*/
|
||||
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
|
||||
|
||||
static final BiMap<ChatColor, String> stylesToNames;
|
||||
|
||||
static {
|
||||
final ImmutableBiMap.Builder<ChatColor, String> builder = ImmutableBiMap.builder();
|
||||
for (final ChatColor style : ChatColor.values()) {
|
||||
if (!style.isFormat()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String styleName;
|
||||
switch (style) {
|
||||
case MAGIC:
|
||||
styleName = "obfuscated";
|
||||
break;
|
||||
case UNDERLINE:
|
||||
styleName = "underlined";
|
||||
break;
|
||||
default:
|
||||
styleName = style.name().toLowerCase();
|
||||
break;
|
||||
}
|
||||
|
||||
builder.put(style, styleName);
|
||||
}
|
||||
stylesToNames = builder.build();
|
||||
}
|
||||
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(MessagePart.class);
|
||||
}
|
||||
|
||||
ChatColor color = ChatColor.WHITE;
|
||||
ArrayList<ChatColor> styles = new ArrayList<ChatColor>();
|
||||
String clickActionName = null, clickActionData = null, hoverActionName = null;
|
||||
JsonRepresentedObject hoverActionData = null;
|
||||
TextualComponent text = null;
|
||||
String insertionData = null;
|
||||
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<JsonRepresentedObject>();
|
||||
|
||||
MessagePart(final TextualComponent text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
MessagePart() {
|
||||
text = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MessagePart deserialize(final Map<String, Object> serialized) {
|
||||
final MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
||||
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
||||
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
||||
part.hoverActionName = (String) serialized.get("hoverActionName");
|
||||
part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
|
||||
part.clickActionName = (String) serialized.get("clickActionName");
|
||||
part.clickActionData = (String) serialized.get("clickActionData");
|
||||
part.insertionData = (String) serialized.get("insertion");
|
||||
part.translationReplacements = (ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
|
||||
return part;
|
||||
}
|
||||
|
||||
boolean hasText() {
|
||||
return text != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public MessagePart clone() throws CloneNotSupportedException {
|
||||
final MessagePart obj = (MessagePart) super.clone();
|
||||
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
||||
if (hoverActionData instanceof JsonString) {
|
||||
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
||||
} else if (hoverActionData instanceof FancyMessage) {
|
||||
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
||||
}
|
||||
obj.translationReplacements = (ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(final JsonWriter json) {
|
||||
try {
|
||||
json.beginObject();
|
||||
text.writeJson(json);
|
||||
json.name("color").value(color.name().toLowerCase());
|
||||
for (final ChatColor style : styles) {
|
||||
json.name(stylesToNames.get(style)).value(true);
|
||||
}
|
||||
if ((clickActionName != null) && (clickActionData != null)) {
|
||||
json.name("clickEvent").beginObject().name("action").value(clickActionName).name("value").value(clickActionData).endObject();
|
||||
}
|
||||
if ((hoverActionName != null) && (hoverActionData != null)) {
|
||||
json.name("hoverEvent").beginObject().name("action").value(hoverActionName).name("value");
|
||||
hoverActionData.writeJson(json);
|
||||
json.endObject();
|
||||
}
|
||||
if (insertionData != null) {
|
||||
json.name("insertion").value(insertionData);
|
||||
}
|
||||
if ((!translationReplacements.isEmpty()) && (text != null) && TextualComponent.isTranslatableText(text)) {
|
||||
json.name("with").beginArray();
|
||||
for (final JsonRepresentedObject obj : translationReplacements) {
|
||||
obj.writeJson(json);
|
||||
}
|
||||
json.endArray();
|
||||
}
|
||||
json.endObject();
|
||||
} catch (final IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "A problem occurred during writing of JSON string", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
final HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("text", text);
|
||||
map.put("styles", styles);
|
||||
map.put("color", color.getChar());
|
||||
map.put("hoverActionName", hoverActionName);
|
||||
map.put("hoverActionData", hoverActionData);
|
||||
map.put("clickActionName", clickActionName);
|
||||
map.put("clickActionData", clickActionData);
|
||||
map.put("insertion", insertionData);
|
||||
map.put("translationReplacements", translationReplacements);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
227
Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java
Normal file
227
Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java
Normal file
@ -0,0 +1,227 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class containing static utility methods and caches which are intended as reflective conveniences.
|
||||
* Unless otherwise noted, upon failure methods will return {@code null}.
|
||||
*/
|
||||
public final class Reflection {
|
||||
|
||||
/**
|
||||
* Stores loaded classes from the {@code net.minecraft.server} package.
|
||||
*/
|
||||
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>();
|
||||
/**
|
||||
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
|
||||
*/
|
||||
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>();
|
||||
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>();
|
||||
/**
|
||||
* Contains loaded methods in a cache.
|
||||
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
||||
*/
|
||||
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
|
||||
private static String _versionString;
|
||||
|
||||
private Reflection() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version string from the package name of the CraftBukkit server implementation.
|
||||
* This is needed to bypass the JAR package name changing on each update.
|
||||
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
|
||||
*/
|
||||
public synchronized static String getVersion() {
|
||||
if (_versionString == null) {
|
||||
if (Bukkit.getServer() == null) {
|
||||
// The server hasn't started, static initializer call?
|
||||
return null;
|
||||
}
|
||||
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
return _versionString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
|
||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
|
||||
* @param className The name of the class, excluding the package, within NMS.
|
||||
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
|
||||
*/
|
||||
public synchronized static Class<?> getNMSClass(final String className) {
|
||||
if (_loadedNMSClasses.containsKey(className)) {
|
||||
return _loadedNMSClasses.get(className);
|
||||
}
|
||||
|
||||
final String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
_loadedNMSClasses.put(className, null);
|
||||
return null;
|
||||
}
|
||||
_loadedNMSClasses.put(className, clazz);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
|
||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this
|
||||
* method simultaneously).
|
||||
* @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory
|
||||
* .CraftItemStack}.
|
||||
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
|
||||
*/
|
||||
public synchronized static Class<?> getOBCClass(final String className) {
|
||||
if (_loadedOBCClasses.containsKey(className)) {
|
||||
return _loadedOBCClasses.get(className);
|
||||
}
|
||||
|
||||
final String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
_loadedOBCClasses.put(className, null);
|
||||
return null;
|
||||
}
|
||||
_loadedOBCClasses.put(className, clazz);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the NMS handle of a CraftBukkit object.
|
||||
* <p>
|
||||
* The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the
|
||||
* runtime type of the specified object.
|
||||
* </p>
|
||||
* @param obj The object for which to retrieve an NMS handle.
|
||||
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
||||
*/
|
||||
public synchronized static Object getHandle(final Object obj) {
|
||||
try {
|
||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
|
||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||
* returned will be an instance or static field.
|
||||
* <p>
|
||||
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
|
||||
* no field will be reflectively looked up twice.
|
||||
* </p>
|
||||
* <p>
|
||||
* If a field is deemed suitable for return,
|
||||
* {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
|
||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||
* </p>
|
||||
* @param clazz The class which contains the field to retrieve.
|
||||
* @param name The declared name of the field in the class.
|
||||
* @return A field object with the specified name declared by the specified class.
|
||||
* @see Class#getDeclaredField(String)
|
||||
*/
|
||||
public synchronized static Field getField(final Class<?> clazz, final String name) {
|
||||
Map<String, Field> loaded;
|
||||
if (!_loadedFields.containsKey(clazz)) {
|
||||
loaded = new HashMap<>();
|
||||
_loadedFields.put(clazz, loaded);
|
||||
} else {
|
||||
loaded = _loadedFields.get(clazz);
|
||||
}
|
||||
if (loaded.containsKey(name)) {
|
||||
// If the field is loaded (or cached as not existing), return the relevant value, which might be null
|
||||
return loaded.get(name);
|
||||
}
|
||||
try {
|
||||
final Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
loaded.put(name, field);
|
||||
return field;
|
||||
} catch (NoSuchFieldException e) {
|
||||
// Error loading
|
||||
e.printStackTrace();
|
||||
// Cache field as not existing
|
||||
loaded.put(name, null);
|
||||
return null;
|
||||
} catch (SecurityException e) {
|
||||
// Error loading
|
||||
e.printStackTrace();
|
||||
// Cache field as not existing
|
||||
loaded.put(name, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
|
||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||
* returned will be an instance or static field.
|
||||
* <p>
|
||||
* A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that
|
||||
* no method will be reflectively looked up twice.
|
||||
* </p>
|
||||
* <p>
|
||||
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
|
||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||
* </p>
|
||||
* <p>
|
||||
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
|
||||
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
|
||||
* @param clazz The class which contains the method to retrieve.
|
||||
* @param name The declared name of the method in the class.
|
||||
* @param args The formal argument types of the method.
|
||||
* @return A method object with the specified name declared by the specified class.
|
||||
*/
|
||||
public synchronized static Method getMethod(final Class<?> clazz, final String name, final Class<?>... args) {
|
||||
if (!_loadedMethods.containsKey(clazz)) {
|
||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||
}
|
||||
|
||||
final Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
|
||||
if (!loadedMethodNames.containsKey(name)) {
|
||||
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
||||
}
|
||||
|
||||
final Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
|
||||
final ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
|
||||
if (loadedSignatures.containsKey(wrappedArg)) {
|
||||
return loadedSignatures.get(wrappedArg);
|
||||
}
|
||||
|
||||
for (final Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
|
||||
m.setAccessible(true);
|
||||
loadedSignatures.put(wrappedArg, m);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
loadedSignatures.put(wrappedArg, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,293 @@
|
||||
package com.plotsquared.bukkit.chat;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a textual component of a message part.
|
||||
* This can be used to not only represent string literals in a JSON message,
|
||||
* but also to represent localized strings and other text values.
|
||||
* <p>Different instances of this class can be created with static constructor methods.</p>
|
||||
*/
|
||||
public abstract class TextualComponent implements Cloneable {
|
||||
|
||||
static {
|
||||
ConfigurationSerialization.registerClass(TextualComponent.ArbitraryTextTypeComponent.class);
|
||||
ConfigurationSerialization.registerClass(TextualComponent.ComplexTextTypeComponent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getReadableString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The JSON key used to represent text components of this type.
|
||||
*/
|
||||
public abstract String getKey();
|
||||
|
||||
/**
|
||||
* @return A readable String
|
||||
*/
|
||||
public abstract String getReadableString();
|
||||
|
||||
/**
|
||||
* Clones a textual component instance.
|
||||
* The returned object should not reference this textual component instance, but should maintain the same key and value.
|
||||
*/
|
||||
@Override
|
||||
public abstract TextualComponent clone() throws CloneNotSupportedException;
|
||||
|
||||
/**
|
||||
* Writes the text data represented by this textual component to the specified JSON writer object.
|
||||
* A new object within the writer is not started.
|
||||
* @param writer The object to which to write the JSON data.
|
||||
* @throws IOException If an error occurs while writing to the stream.
|
||||
*/
|
||||
public abstract void writeJson(final JsonWriter writer) throws IOException;
|
||||
|
||||
static TextualComponent deserialize(final Map<String, Object> map) {
|
||||
if (map.containsKey("key") && (map.size() == 2) && map.containsKey("value")) {
|
||||
// Arbitrary text component
|
||||
return ArbitraryTextTypeComponent.deserialize(map);
|
||||
} else if ((map.size() >= 2) && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
|
||||
// Complex JSON object
|
||||
return ComplexTextTypeComponent.deserialize(map);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean isTextKey(final String key) {
|
||||
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
|
||||
}
|
||||
|
||||
static boolean isTranslatableText(final TextualComponent component) {
|
||||
return (component instanceof ComplexTextTypeComponent) && ((ComplexTextTypeComponent) component).getKey().equals("translate");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal class used to represent all types of text components.
|
||||
* Exception validating done is on keys and values.
|
||||
*/
|
||||
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
||||
|
||||
public ArbitraryTextTypeComponent(final String key, final String value) {
|
||||
setKey(key);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return _key;
|
||||
}
|
||||
|
||||
public void setKey(final String key) {
|
||||
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
||||
_key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public void setValue(final String value) {
|
||||
Preconditions.checkArgument(value != null, "The value must be specified.");
|
||||
_value = value;
|
||||
}
|
||||
|
||||
private String _key;
|
||||
private String _value;
|
||||
|
||||
@Override
|
||||
public TextualComponent clone() throws CloneNotSupportedException {
|
||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||
return new ArbitraryTextTypeComponent(getKey(), getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(final JsonWriter writer) throws IOException {
|
||||
writer.name(getKey()).value(getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
public Map<String, Object> serialize() {
|
||||
return new HashMap<String, Object>() {
|
||||
{
|
||||
put("key", getKey());
|
||||
put("value", getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ArbitraryTextTypeComponent deserialize(final Map<String, Object> map) {
|
||||
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReadableString() {
|
||||
return getValue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal class used to represent a text component with a nested JSON value.
|
||||
* Exception validating done is on keys and values.
|
||||
*/
|
||||
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
||||
|
||||
public ComplexTextTypeComponent(final String key, final Map<String, String> values) {
|
||||
setKey(key);
|
||||
setValue(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return _key;
|
||||
}
|
||||
|
||||
public void setKey(final String key) {
|
||||
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
||||
_key = key;
|
||||
}
|
||||
|
||||
public Map<String, String> getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public void setValue(final Map<String, String> value) {
|
||||
Preconditions.checkArgument(value != null, "The value must be specified.");
|
||||
_value = value;
|
||||
}
|
||||
|
||||
private String _key;
|
||||
private Map<String, String> _value;
|
||||
|
||||
@Override
|
||||
public TextualComponent clone() throws CloneNotSupportedException {
|
||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||
return new ComplexTextTypeComponent(getKey(), getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(final JsonWriter writer) throws IOException {
|
||||
writer.name(getKey());
|
||||
writer.beginObject();
|
||||
for (final Map.Entry<String, String> jsonPair : _value.entrySet()) {
|
||||
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
|
||||
}
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
public Map<String, Object> serialize() {
|
||||
return new java.util.HashMap<String, Object>() {
|
||||
{
|
||||
put("key", getKey());
|
||||
for (final Map.Entry<String, String> valEntry : getValue().entrySet()) {
|
||||
put("value." + valEntry.getKey(), valEntry.getValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ComplexTextTypeComponent deserialize(final Map<String, Object> map) {
|
||||
String key = null;
|
||||
final Map<String, String> value = new HashMap<String, String>();
|
||||
for (final Map.Entry<String, Object> valEntry : map.entrySet()) {
|
||||
if (valEntry.getKey().equals("key")) {
|
||||
key = (String) valEntry.getValue();
|
||||
} else if (valEntry.getKey().startsWith("value.")) {
|
||||
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
|
||||
}
|
||||
}
|
||||
return new ComplexTextTypeComponent(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReadableString() {
|
||||
return getKey();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a textual component representing a string literal.
|
||||
* This is the default type of textual component when a single string literal is given to a method.
|
||||
* @param textValue The text which will be represented.
|
||||
* @return The text component representing the specified literal text.
|
||||
*/
|
||||
public static TextualComponent rawText(final String textValue) {
|
||||
return new ArbitraryTextTypeComponent("text", textValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a textual component representing a localized string.
|
||||
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a resource pack.
|
||||
* <p>
|
||||
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to the client.
|
||||
* </p>
|
||||
* @param translateKey The string key which maps to localized text.
|
||||
* @return The text component representing the specified localized text.
|
||||
*/
|
||||
public static TextualComponent localizedText(final String translateKey) {
|
||||
return new ArbitraryTextTypeComponent("translate", translateKey);
|
||||
}
|
||||
|
||||
private static void throwUnsupportedSnapshot() {
|
||||
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a textual component representing a scoreboard value.
|
||||
* The client will see their own score for the specified objective as the text represented by this component.
|
||||
* <p>
|
||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||
* </p>
|
||||
* @param scoreboardObjective The name of the objective for which to display the score.
|
||||
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during JSON serialization.
|
||||
*/
|
||||
public static TextualComponent objectiveScore(final String scoreboardObjective) {
|
||||
return objectiveScore("*", scoreboardObjective);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a textual component representing a scoreboard value.
|
||||
* The client will see the score of the specified player for the specified objective as the text represented by this component.
|
||||
* <p>
|
||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||
* </p>
|
||||
* @param playerName The name of the player whos score will be shown. If this string represents the single-character sequence "*", the viewing player's score will be displayed.
|
||||
* Standard minecraft selectors (@a, @p, etc) are <em>not</em> supported.
|
||||
* @param scoreboardObjective The name of the objective for which to display the score.
|
||||
* @return The text component representing the specified scoreboard score for the specified player, or {@code null} if an error occurs during JSON serialization.
|
||||
*/
|
||||
public static TextualComponent objectiveScore(final String playerName, final String scoreboardObjective) {
|
||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
|
||||
|
||||
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String> builder().put("name", playerName).put("objective", scoreboardObjective).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
|
||||
* The client will see the players or entities captured by the specified selector as the text represented by this component.
|
||||
* <p>
|
||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||
* </p>
|
||||
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in the place of this text component.
|
||||
* @return The text component representing the name of the entities captured by the selector.
|
||||
*/
|
||||
public static TextualComponent selector(final String selector) {
|
||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
|
||||
|
||||
return new ArbitraryTextTypeComponent("selector", selector);
|
||||
}
|
||||
}
|
@ -0,0 +1,332 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.AbstractDB;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||
import com.plotsquared.general.commands.Argument;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "uuidconvert",
|
||||
permission = "plots.admin",
|
||||
description = "Debug UUID conversion",
|
||||
usage = "/plot uuidconvert <lower|offline|online>",
|
||||
requiredType = RequiredType.CONSOLE,
|
||||
category = CommandCategory.DEBUG)
|
||||
public class DebugUUID extends SubCommand {
|
||||
|
||||
public DebugUUID() {
|
||||
requiredArguments = new Argument[] { Argument.String };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
||||
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||
final UUIDWrapper newWrapper;
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "lower":
|
||||
newWrapper = new LowerOfflineUUIDWrapper();
|
||||
break;
|
||||
case "offline":
|
||||
newWrapper = new OfflineUUIDWrapper();
|
||||
break;
|
||||
case "online":
|
||||
newWrapper = new DefaultUUIDWrapper();
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
final Class<?> clazz = Class.forName(args[0]);
|
||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != 2 || !"-o".equals(args[1])) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf the process is interrupted, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||
MainUtil.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
|
||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
||||
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
entry.getValue().kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Initializing map");
|
||||
|
||||
final HashMap<UUID, UUID> uCMap = new HashMap<>();
|
||||
final HashMap<UUID, UUID> uCReverse = new HashMap<>();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Collecting playerdata");
|
||||
|
||||
final HashSet<String> worlds = new HashSet<>();
|
||||
worlds.add(WorldUtil.IMP.getMainWorld());
|
||||
worlds.add("world");
|
||||
final HashSet<UUID> uuids = new HashSet<>();
|
||||
final HashSet<String> names = new HashSet<>();
|
||||
for (final String worldname : worlds) {
|
||||
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null)
|
||||
for (final String current : dat) {
|
||||
final String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(player, C.PREFIX.s() + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
final File playersFolder = new File(worldname + File.separator + "players");
|
||||
dat = playersFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null) {
|
||||
for (final String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating map");
|
||||
UUID uuid2;
|
||||
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||
uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
MainUtil.sendMessage(player, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (final String name : names) {
|
||||
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||
uuid2 = newWrapper.getUUID(name);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
if (uCMap.isEmpty()) {
|
||||
MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
|
||||
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||
if (op.getLastPlayed() != 0) {
|
||||
// String name = op.getName();
|
||||
// StringWrapper wrap = new StringWrapper(name);
|
||||
final UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uCMap.isEmpty()) {
|
||||
MainUtil.sendMessage(player, "&cError. Failed to collect UUIDs!");
|
||||
return false;
|
||||
} else {
|
||||
MainUtil.sendMessage(player, "&a - Successfully repopulated");
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
final String name = UUIDHandler.getName(entry.getKey());
|
||||
if (name != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
||||
|
||||
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
final String[] split = line.split("\\|");
|
||||
final String name = split[0];
|
||||
if (name.isEmpty() || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
final UUID old = currentUUIDWrapper.getUUID(name);
|
||||
if (old == null) {
|
||||
continue;
|
||||
}
|
||||
final UUID now = newWrapper.getUUID(name);
|
||||
UUIDHandler.add(new StringWrapper(name), now);
|
||||
uCMap.put(old, now);
|
||||
uCReverse.put(now, old);
|
||||
} catch (final Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing wrapper");
|
||||
UUIDHandler.setUUIDWrapper(newWrapper);
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||
|
||||
for (final Plot plot : PS.get().getPlots()) {
|
||||
final UUID value = uCMap.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
plot.getTrusted().clear();
|
||||
plot.getMembers().clear();
|
||||
plot.getDenied().clear();
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Deleting database");
|
||||
final AbstractDB database = DBFunc.dbManager;
|
||||
final boolean result = database.deleteTables();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Creating tables");
|
||||
|
||||
try {
|
||||
database.createTables();
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||
for (final Plot plot : PS.get().getPlots()) {
|
||||
final UUID value = uCReverse.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
}
|
||||
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", true);
|
||||
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (IOException e) {
|
||||
MainUtil.sendMessage(player, "Could not save configuration. It will need to be manuall set!");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||
database.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&aConversion complete!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
||||
MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.plotsquared.bukkit.database.plotme;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public abstract class APlotMeConnector {
|
||||
public abstract Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder);
|
||||
|
||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(final Connection connection) throws SQLException;
|
||||
|
||||
public abstract boolean accepts(final String version);
|
||||
|
||||
public String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean isValidConnection(final Connection connection) {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
public void copyConfig(final FileConfiguration plotConfig, final String world, final String actualWorldName) {
|
||||
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth);
|
||||
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize);
|
||||
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock);
|
||||
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
||||
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
||||
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
||||
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
}
|
||||
|
||||
public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 256, z);
|
||||
}
|
||||
|
||||
public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) {
|
||||
final int px = plotid.x;
|
||||
final int pz = plotid.y;
|
||||
final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1;
|
||||
return new Location(null, x, 1, z);
|
||||
}
|
||||
|
||||
public void setMerged(final HashMap<String, HashMap<PlotId, boolean[]>> merges, final String world, final PlotId id, final int direction) {
|
||||
final HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||
PlotId id2;
|
||||
switch (direction) {
|
||||
case 0: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
id2 = new PlotId(id.x, id.y);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean[] merge1;
|
||||
boolean[] merge2;
|
||||
if (plots.containsKey(id)) {
|
||||
merge1 = plots.get(id);
|
||||
} else {
|
||||
merge1 = new boolean[] { false, false, false, false };
|
||||
}
|
||||
if (plots.containsKey(id2)) {
|
||||
merge2 = plots.get(id2);
|
||||
} else {
|
||||
merge2 = new boolean[] { false, false, false, false };
|
||||
}
|
||||
merge1[direction] = true;
|
||||
merge2[(direction + 2) % 4] = true;
|
||||
plots.put(id, merge1);
|
||||
plots.put(id2, merge1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,267 @@
|
||||
package com.plotsquared.bukkit.database.plotme;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ClassicPlotMeConnector extends APlotMeConnector {
|
||||
|
||||
private String plugin;
|
||||
private String prefix;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
prefix = plotConfig.getString("mySQLprefix");
|
||||
if (prefix == null) {
|
||||
prefix = plugin.toLowerCase();
|
||||
}
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
||||
} else {
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
} catch (SQLException | ClassNotFoundException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(final Connection connection) throws SQLException {
|
||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
PreparedStatement stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "Plots`");
|
||||
ResultSet r = stmt.executeQuery();
|
||||
String column = null;
|
||||
final boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
||||
final boolean checkUUID2 = DBFunc.hasColumn(r, "ownerId");
|
||||
if (checkUUID) {
|
||||
column = "ownerid";
|
||||
} else if (checkUUID2) {
|
||||
column = "ownerId";
|
||||
}
|
||||
final boolean merge = !"plotme".equalsIgnoreCase(plugin) && Settings.CONVERT_PLOTME;
|
||||
int missing = 0;
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("owner");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
plots.put(world, new HashMap<PlotId, Plot>());
|
||||
if (merge) {
|
||||
final int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
final int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId, boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
final int tx = r.getInt("topX");
|
||||
final int tz = r.getInt("topZ");
|
||||
final int bx = r.getInt("bottomX") - 1;
|
||||
final int bz = r.getInt("bottomZ") - 1;
|
||||
final int path = roadWidth.get(world);
|
||||
final int plot = plotWidth.get(world);
|
||||
final Location top = getPlotTopLocAbs(path, plot, id);
|
||||
final Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name, null);
|
||||
if (owner == null) {
|
||||
if ("*".equals(name)) {
|
||||
owner = DBFunc.everyone;
|
||||
} else {
|
||||
if (checkUUID || checkUUID2) {
|
||||
try {
|
||||
final byte[] bytes = r.getBytes(column);
|
||||
if (bytes != null) {
|
||||
try {
|
||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
final long high = bb.getLong();
|
||||
final long low = bb.getLong();
|
||||
owner = new UUID(high, low);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
if (!name.isEmpty()) {
|
||||
owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
missing++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
final Plot plot = new Plot(PlotArea.createGeneric(world), id, owner);
|
||||
plots.get(world).put(id, plot);
|
||||
}
|
||||
if (missing > 0) {
|
||||
PS.log("&cSome names could not be identified:");
|
||||
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
||||
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
||||
PS.log("&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will remain unknown until the player connects)");
|
||||
}
|
||||
|
||||
for (final Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
||||
final String world = entry.getKey();
|
||||
for (final Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
||||
final HashMap<PlotId, Plot> newplots = plots.get(world);
|
||||
final Plot plot = newplots.get(entry2.getKey());
|
||||
if (plot != null) {
|
||||
plot.setMerged(entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
try {
|
||||
|
||||
PS.log(" - " + prefix + "Denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "Denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID denied = UUIDHandler.getUUID(name, null);
|
||||
if (denied == null) {
|
||||
if ("*".equals(name)) {
|
||||
denied = DBFunc.everyone;
|
||||
} else {
|
||||
if (DBFunc.hasColumn(r, "playerid")) {
|
||||
try {
|
||||
final byte[] bytes = r.getBytes("playerid");
|
||||
if (bytes != null) {
|
||||
try {
|
||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
final long high = bb.getLong();
|
||||
final long low = bb.getLong();
|
||||
denied = new UUID(high, low);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
denied = UUID.nameUUIDFromBytes(bytes);
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), denied);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (denied == null) {
|
||||
PS.log("&6Could not identify denied for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).getDenied().add(denied);
|
||||
}
|
||||
}
|
||||
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("player");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
UUID helper = UUIDHandler.getUUID(name, null);
|
||||
if (helper == null) {
|
||||
if ("*".equals(name)) {
|
||||
helper = DBFunc.everyone;
|
||||
} else {
|
||||
if (DBFunc.hasColumn(r, "playerid")) {
|
||||
try {
|
||||
final byte[] bytes = r.getBytes("playerid");
|
||||
if (bytes != null) {
|
||||
try {
|
||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
final long high = bb.getLong();
|
||||
final long low = bb.getLong();
|
||||
helper = new UUID(high, low);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
helper = UUID.nameUUIDFromBytes(bytes);
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), helper);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (helper == null) {
|
||||
PS.log("&6Could not identify helper for plot: " + id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (plots.get(world).containsKey(id)) {
|
||||
plots.get(world).get(id).getTrusted().add(helper);
|
||||
}
|
||||
}
|
||||
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(final String version) {
|
||||
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get().canUpdate("0.999.999", version);
|
||||
}
|
||||
}
|
@ -0,0 +1,406 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.database.plotme;
|
||||
|
||||
import com.intellectualcrafters.configuration.MemorySection;
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Created 2014-08-17 for PlotSquared
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class LikePlotMeConverter {
|
||||
private final String plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plugin Plugin Used to run the converter
|
||||
*/
|
||||
public LikePlotMeConverter(final String plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static String getWorld(final String world) {
|
||||
for (final World newworld : Bukkit.getWorlds()) {
|
||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||
return newworld.getName();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
private void sendMessage(final String message) {
|
||||
PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||
}
|
||||
|
||||
public String getPlotMePath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public String getAthionPlotsPath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||
}
|
||||
|
||||
public FileConfiguration getPlotMeConfig(final String dataFolder) {
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
}
|
||||
|
||||
public Set<String> getPlotMeWorlds(final FileConfiguration plotConfig) {
|
||||
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
}
|
||||
|
||||
public void mergeWorldYml(final String plugin, FileConfiguration plotConfig) {
|
||||
try {
|
||||
File genConfig = new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||
if (genConfig.exists()) {
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
||||
for (String key : yml.getKeys(true)) {
|
||||
if (!plotConfig.contains(key)) {
|
||||
Object value = yml.get(key);
|
||||
if (!(value instanceof MemorySection)) {
|
||||
plotConfig.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateWorldYml(final String plugin, final String location) {
|
||||
try {
|
||||
final Path path = Paths.get(location);
|
||||
final File file = new File(location);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
final Charset charset = StandardCharsets.UTF_8;
|
||||
String content = new String(Files.readAllBytes(path), charset);
|
||||
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
||||
content = content.replaceAll(plugin, "PlotSquared");
|
||||
Files.write(path, content.getBytes(charset));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean run(final APlotMeConnector connector) {
|
||||
try {
|
||||
final String dataFolder = getPlotMePath();
|
||||
final FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||
if (plotConfig == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String version = plotConfig.getString("Version");
|
||||
if (version == null) {
|
||||
version = plotConfig.getString("version");
|
||||
}
|
||||
if (!connector.accepts(version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||
|
||||
final Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||
|
||||
if (!connector.isValidConnection(connection)) {
|
||||
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
|
||||
|
||||
mergeWorldYml(plugin, plotConfig);
|
||||
|
||||
sendMessage("Connecting to " + plugin + " DB");
|
||||
|
||||
int plotCount = 0;
|
||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||
|
||||
sendMessage("Collecting plot data");
|
||||
|
||||
final String dbPrefix = plugin.toLowerCase();
|
||||
sendMessage(" - " + dbPrefix + "Plots");
|
||||
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||
|
||||
if (Settings.CONVERT_PLOTME) {
|
||||
sendMessage("Updating bukkit.yml");
|
||||
updateWorldYml(plugin, "bukkit.yml");
|
||||
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
||||
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
||||
sendMessage("Copying config for: " + world);
|
||||
try {
|
||||
final String actualWorldName = getWorld(world);
|
||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
||||
}
|
||||
}
|
||||
}
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
||||
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
plotCount += entry.getValue().size();
|
||||
}
|
||||
if (!Settings.CONVERT_PLOTME) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sendMessage(" - " + dbPrefix + "Allowed");
|
||||
|
||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||
if (PLOTME_DG_FILE.exists()) {
|
||||
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
||||
try {
|
||||
for (final String world : plots.keySet()) {
|
||||
final String actualWorldName = getWorld(world);
|
||||
final String plotMeWorldName = world.toLowerCase();
|
||||
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||
/*
|
||||
* TODO: dead code
|
||||
*
|
||||
if (pathwidth == null) {
|
||||
pathwidth = 7;
|
||||
}
|
||||
*/
|
||||
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
||||
|
||||
Integer pathheight = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||
if (pathheight == 0) {
|
||||
pathheight = 64;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.height", pathheight);
|
||||
PS.get().config.set("worlds." + world + ".wall.height", pathheight);
|
||||
PS.get().config.set("worlds." + world + ".plot.height", pathheight);
|
||||
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
||||
if (plotsize == 0) {
|
||||
plotsize = 32;
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
||||
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
||||
if (wallblock == null) {
|
||||
wallblock = "44";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
||||
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
||||
if (floor == null) {
|
||||
floor = "2";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
||||
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
||||
if (filling == null) {
|
||||
filling = "3";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
||||
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
||||
if (road == null) {
|
||||
road = "5";
|
||||
}
|
||||
PS.get().config.set("worlds." + world + ".road.block", road);
|
||||
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||
if (height == 0) {
|
||||
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
||||
if (height == 0) {
|
||||
height = 64;
|
||||
}
|
||||
}
|
||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
||||
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
PlotArea area = PS.get().getPlotArea(world, null);
|
||||
int duplicate = 0;
|
||||
if (area != null) {
|
||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||
if (area.getOwnedPlotAbs(entry2.getKey()) != null) {
|
||||
duplicate++;
|
||||
} else {
|
||||
createdPlots.add(entry2.getValue());
|
||||
}
|
||||
}
|
||||
if (duplicate > 0) {
|
||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||
}
|
||||
} else {
|
||||
if (PS.get().plots_tmp != null) {
|
||||
HashMap<PlotId, Plot> map = PS.get().plots_tmp.get(world);
|
||||
if (map != null) {
|
||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||
if (map.containsKey(entry2.getKey())) {
|
||||
duplicate++;
|
||||
} else {
|
||||
createdPlots.add(entry2.getValue());
|
||||
}
|
||||
}
|
||||
if (duplicate > 0) {
|
||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
createdPlots.addAll(entry.getValue().values());
|
||||
}
|
||||
}
|
||||
sendMessage("Creating plot DB");
|
||||
Thread.sleep(1000);
|
||||
final AtomicBoolean done = new AtomicBoolean(false);
|
||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (done.get()) {
|
||||
done();
|
||||
sendMessage("&aDatabase conversion is now complete!");
|
||||
PS.debug("&c - Stop the server");
|
||||
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||
PS.debug("&c - Start the server");
|
||||
PS.get().setPlots(DBFunc.getPlots());
|
||||
} else {
|
||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||
done.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
sendMessage("Saving configuration...");
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
sendMessage(" - &cFailed to save configuration.");
|
||||
}
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
boolean MV = false;
|
||||
boolean MW = false;
|
||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
MV = true;
|
||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
MW = true;
|
||||
}
|
||||
for (final String worldname : worlds) {
|
||||
final World world = Bukkit.getWorld(getWorld(worldname));
|
||||
if (world == null) {
|
||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
||||
}
|
||||
final String actualWorldName = world.getName();
|
||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
||||
PS.get().removePlotAreas(actualWorldName);
|
||||
if (MV) {
|
||||
// unload world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MV
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
||||
} else if (MW) {
|
||||
// unload world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// load world with MW
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||
} else {
|
||||
// Load using Bukkit API
|
||||
// - User must set generator manually
|
||||
Bukkit.getServer().unloadWorld(world, true);
|
||||
final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
|
||||
myworld.save();
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (done.get()) {
|
||||
done();
|
||||
sendMessage("&aDatabase conversion is now complete!");
|
||||
PS.debug("&c - Stop the server");
|
||||
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||
PS.debug("&c - Start the server");
|
||||
} else {
|
||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||
done.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
PS.debug("&/end/");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void done() {
|
||||
PS.get().setPlots(DBFunc.getPlots());
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
package com.plotsquared.bukkit.database.plotme;
|
||||
|
||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLite;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlotMeConnector_017 extends APlotMeConnector {
|
||||
private String plugin;
|
||||
|
||||
@Override
|
||||
public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) {
|
||||
this.plugin = plugin.toLowerCase();
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
} else {
|
||||
final File file = new File(dataFolder + File.separator + "plotmecore.db");
|
||||
if (file.exists()) {
|
||||
return new SQLite(dataFolder + File.separator + "plotmecore.db").openConnection();
|
||||
}
|
||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||
}
|
||||
} catch (SQLException | ClassNotFoundException e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(final Connection connection) throws SQLException {
|
||||
ResultSet r;
|
||||
PreparedStatement stmt;
|
||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||
final HashMap<Integer, Plot> plots = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||
try {
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`");
|
||||
r = stmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
PS.debug("========= Table does not exist =========");
|
||||
e.printStackTrace();
|
||||
PS.debug("=======================================");
|
||||
PS.debug("&8 - &7The database does not match the version specified in the PlotMe config");
|
||||
PS.debug("&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3");
|
||||
return null;
|
||||
}
|
||||
final boolean checkUUID = DBFunc.hasColumn(r, "ownerID");
|
||||
final boolean merge = !plugin.equals("plotme") && Settings.CONVERT_PLOTME;
|
||||
while (r.next()) {
|
||||
final int key = r.getInt("plot_id");
|
||||
final PlotId id = new PlotId(r.getInt("plotX"), r.getInt("plotZ"));
|
||||
final String name = r.getString("owner");
|
||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
||||
if (!plots.containsKey(world)) {
|
||||
if (merge) {
|
||||
final int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||
final int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||
plotWidth.put(world, plot);
|
||||
roadWidth.put(world, path);
|
||||
merges.put(world, new HashMap<PlotId, boolean[]>());
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
final int tx = r.getInt("topX");
|
||||
final int tz = r.getInt("topZ");
|
||||
final int bx = r.getInt("bottomX") - 1;
|
||||
final int bz = r.getInt("bottomZ") - 1;
|
||||
final int path = roadWidth.get(world);
|
||||
final int plot = plotWidth.get(world);
|
||||
final Location top = getPlotTopLocAbs(path, plot, id);
|
||||
final Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||
if (tx > top.getX()) {
|
||||
setMerged(merges, world, id, 1);
|
||||
}
|
||||
if (tz > top.getZ()) {
|
||||
setMerged(merges, world, id, 2);
|
||||
}
|
||||
if (bx < bot.getX()) {
|
||||
setMerged(merges, world, id, 3);
|
||||
}
|
||||
if (bz > bot.getZ()) {
|
||||
setMerged(merges, world, id, 0);
|
||||
}
|
||||
}
|
||||
UUID owner = UUIDHandler.getUUID(name, null);
|
||||
if (owner == null) {
|
||||
if (name.equals("*")) {
|
||||
owner = DBFunc.everyone;
|
||||
} else {
|
||||
if (checkUUID) {
|
||||
try {
|
||||
final byte[] bytes = r.getBytes("ownerid");
|
||||
if (bytes != null) {
|
||||
owner = UUID.nameUUIDFromBytes(bytes);
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (owner == null) {
|
||||
PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
UUIDHandler.add(new StringWrapper(name), owner);
|
||||
}
|
||||
final Plot plot = new Plot(PlotArea.createGeneric(world), id, owner);
|
||||
plots.put(key, plot);
|
||||
}
|
||||
for (final Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
final Plot plot = entry.getValue();
|
||||
final HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.getArea().worldname);
|
||||
if (mergeMap != null) {
|
||||
if (mergeMap.containsKey(plot.getId())) {
|
||||
plot.setMerged(mergeMap.get(plot.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
try {
|
||||
PS.log(" - " + plugin + "core_denied");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_denied`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final int key = r.getInt("plot_id");
|
||||
final Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
PS.log("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
final UUID denied = UUID.fromString(r.getString("player"));
|
||||
plot.getDenied().add(denied);
|
||||
}
|
||||
|
||||
PS.log(" - " + plugin + "core_allowed");
|
||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_allowed`");
|
||||
r = stmt.executeQuery();
|
||||
|
||||
while (r.next()) {
|
||||
final int key = r.getInt("plot_id");
|
||||
final Plot plot = plots.get(key);
|
||||
if (plot == null) {
|
||||
PS.log("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
||||
continue;
|
||||
}
|
||||
final UUID allowed = UUID.fromString(r.getString("player"));
|
||||
plot.getTrusted().add(allowed);
|
||||
}
|
||||
r.close();
|
||||
stmt.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final HashMap<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
|
||||
|
||||
for (final Entry<Integer, Plot> entry : plots.entrySet()) {
|
||||
final Plot plot = entry.getValue();
|
||||
HashMap<PlotId, Plot> map = processed.get(plot.getArea().worldname);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
processed.put(plot.getArea().worldname, map);
|
||||
}
|
||||
map.put(plot.getId(), plot);
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(final String version) {
|
||||
if (version == null) {
|
||||
return false;
|
||||
}
|
||||
return !PS.get().canUpdate(version, "0.17");
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
class AgeableStats {
|
||||
|
||||
int age;
|
||||
boolean locked;
|
||||
boolean adult;
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
class ArmorStandStats {
|
||||
|
||||
final float[] head = new float[3];
|
||||
final float[] body = new float[3];
|
||||
final float[] leftLeg = new float[3];
|
||||
final float[] rightLeg = new float[3];
|
||||
final float[] leftArm = new float[3];
|
||||
final float[] rightArm = new float[3];
|
||||
boolean arms;
|
||||
boolean noPlate;
|
||||
boolean invisible;
|
||||
boolean small;
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
class EntityBaseStats {
|
||||
|
||||
EntityWrapper passenger;
|
||||
float fall;
|
||||
short fire;
|
||||
int age;
|
||||
double vZ;
|
||||
double vY;
|
||||
double vX;
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public abstract class EntityWrapper {
|
||||
|
||||
protected final float yaw;
|
||||
protected final float pitch;
|
||||
private final Entity entity;
|
||||
private final EntityType type;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
EntityWrapper(final @NonNull Entity entity) {
|
||||
this.entity = entity;
|
||||
this.type = entity.getType();
|
||||
|
||||
final Location location = entity.getLocation();
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.yaw = location.getYaw();
|
||||
this.pitch = location.getPitch();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
||||
}
|
||||
|
||||
public abstract Entity spawn(World world, int xOffset, int zOffset);
|
||||
|
||||
public abstract void saveEntity();
|
||||
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return this.entity;
|
||||
}
|
||||
|
||||
public EntityType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import org.bukkit.entity.Horse;
|
||||
|
||||
class HorseStats {
|
||||
|
||||
double jump;
|
||||
boolean chest;
|
||||
Horse.Variant variant;
|
||||
Horse.Color color;
|
||||
Horse.Style style;
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class LivingEntityStats {
|
||||
|
||||
boolean loot;
|
||||
String name;
|
||||
boolean visible;
|
||||
float health;
|
||||
short air;
|
||||
boolean persistent;
|
||||
boolean leashed;
|
||||
short leashX;
|
||||
short leashY;
|
||||
short leashZ;
|
||||
boolean equipped;
|
||||
ItemStack mainHand;
|
||||
ItemStack helmet;
|
||||
ItemStack boots;
|
||||
ItemStack leggings;
|
||||
ItemStack chestplate;
|
||||
Collection<PotionEffect> potions;
|
||||
ItemStack offHand;
|
||||
|
||||
}
|
@ -1,763 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Bat;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Rabbit;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + ReplicatingEntityWrapper.class.getSimpleName());
|
||||
|
||||
private final short depth;
|
||||
private final int hash;
|
||||
private final EntityBaseStats base = new EntityBaseStats();
|
||||
|
||||
private ItemStack[] inventory;
|
||||
// Extended
|
||||
private ItemStack stack;
|
||||
private byte dataByte;
|
||||
private byte dataByte2;
|
||||
private String dataString;
|
||||
private LivingEntityStats lived;
|
||||
private AgeableStats aged;
|
||||
private TameableStats tamed;
|
||||
private ArmorStandStats stand;
|
||||
private HorseStats horse;
|
||||
private boolean noGravity;
|
||||
|
||||
public ReplicatingEntityWrapper(Entity entity, short depth) {
|
||||
super(entity);
|
||||
|
||||
this.hash = entity.getEntityId();
|
||||
this.depth = depth;
|
||||
|
||||
if (depth == 0) {
|
||||
return;
|
||||
}
|
||||
List<Entity> passengers = entity.getPassengers();
|
||||
if (passengers.size() > 0) {
|
||||
this.base.passenger = new ReplicatingEntityWrapper(passengers.get(0), depth);
|
||||
}
|
||||
this.base.fall = entity.getFallDistance();
|
||||
this.base.fire = (short) entity.getFireTicks();
|
||||
this.base.age = entity.getTicksLived();
|
||||
Vector velocity = entity.getVelocity();
|
||||
this.base.vX = velocity.getX();
|
||||
this.base.vY = velocity.getY();
|
||||
this.base.vZ = velocity.getZ();
|
||||
if (depth == 1) {
|
||||
return;
|
||||
}
|
||||
if (!entity.hasGravity()) {
|
||||
this.noGravity = true;
|
||||
}
|
||||
switch (entity.getType().toString()) {
|
||||
case "BOAT":
|
||||
Boat boat = (Boat) entity;
|
||||
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
|
||||
return;
|
||||
case "ARROW":
|
||||
case "EGG":
|
||||
case "ENDER_CRYSTAL":
|
||||
case "ENDER_PEARL":
|
||||
case "ENDER_SIGNAL":
|
||||
case "EXPERIENCE_ORB":
|
||||
case "FALLING_BLOCK":
|
||||
case "FIREBALL":
|
||||
case "FIREWORK":
|
||||
case "FISHING_HOOK":
|
||||
case "LEASH_HITCH":
|
||||
case "LIGHTNING":
|
||||
case "MINECART":
|
||||
case "MINECART_COMMAND":
|
||||
case "MINECART_MOB_SPAWNER":
|
||||
case "MINECART_TNT":
|
||||
case "PLAYER":
|
||||
case "PRIMED_TNT":
|
||||
case "SLIME":
|
||||
case "SMALL_FIREBALL":
|
||||
case "SNOWBALL":
|
||||
case "MINECART_FURNACE":
|
||||
case "SPLASH_POTION":
|
||||
case "THROWN_EXP_BOTTLE":
|
||||
case "WITHER_SKULL":
|
||||
case "UNKNOWN":
|
||||
case "SPECTRAL_ARROW":
|
||||
case "SHULKER_BULLET":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "AREA_EFFECT_CLOUD":
|
||||
case "TRIDENT":
|
||||
case "LLAMA_SPIT":
|
||||
// Do this stuff later
|
||||
return;
|
||||
// MISC //
|
||||
case "DROPPED_ITEM":
|
||||
Item item = (Item) entity;
|
||||
this.stack = item.getItemStack();
|
||||
return;
|
||||
case "ITEM_FRAME":
|
||||
this.x = Math.floor(this.getX());
|
||||
this.y = Math.floor(this.getY());
|
||||
this.z = Math.floor(this.getZ());
|
||||
ItemFrame itemFrame = (ItemFrame) entity;
|
||||
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
|
||||
this.stack = itemFrame.getItem().clone();
|
||||
return;
|
||||
case "PAINTING":
|
||||
this.x = Math.floor(this.getX());
|
||||
this.y = Math.floor(this.getY());
|
||||
this.z = Math.floor(this.getZ());
|
||||
Painting painting = (Painting) entity;
|
||||
Art art = painting.getArt();
|
||||
this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
||||
int h = art.getBlockHeight();
|
||||
if (h % 2 == 0) {
|
||||
this.y -= 1;
|
||||
}
|
||||
this.dataString = art.name();
|
||||
return;
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case "MINECART_CHEST":
|
||||
case "MINECART_HOPPER":
|
||||
storeInventory((InventoryHolder) entity);
|
||||
return;
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case "HORSE":
|
||||
case "DONKEY":
|
||||
case "LLAMA":
|
||||
case "MULE":
|
||||
case "SKELETON_HORSE":
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
this.horse = new HorseStats();
|
||||
this.horse.jump = horse.getJumpStrength();
|
||||
if (horse instanceof ChestedHorse horse1) {
|
||||
this.horse.chest = horse1.isCarryingChest();
|
||||
}
|
||||
//todo these horse features need fixing
|
||||
//this.horse.variant = horse.getVariant();
|
||||
//this.horse.style = horse.getStyle();
|
||||
//this.horse.color = horse.getColor();
|
||||
storeTameable(horse);
|
||||
storeAgeable(horse);
|
||||
storeLiving(horse);
|
||||
storeInventory(horse);
|
||||
return;
|
||||
// END INVENTORY HOLDER //
|
||||
case "WOLF":
|
||||
case "OCELOT":
|
||||
storeTameable((Tameable) entity);
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END TAMEABLE //
|
||||
//todo fix sheep
|
||||
case "SHEEP":
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (sheep.isSheared()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
this.dataByte2 = sheep.getColor().getDyeData();
|
||||
storeAgeable(sheep);
|
||||
storeLiving(sheep);
|
||||
return;
|
||||
case "VILLAGER":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "MUSHROOM_COW":
|
||||
case "PIG":
|
||||
case "TURTLE":
|
||||
case "POLAR_BEAR":
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case "RABBIT":
|
||||
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END AGEABLE //
|
||||
case "ARMOR_STAND":
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
this.inventory =
|
||||
new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
||||
stand.getChestplate().clone(), stand.getLeggings().clone(),
|
||||
stand.getBoots().clone()};
|
||||
storeLiving(stand);
|
||||
this.stand = new ArmorStandStats();
|
||||
|
||||
EulerAngle head = stand.getHeadPose();
|
||||
this.stand.head[0] = (float) head.getX();
|
||||
this.stand.head[1] = (float) head.getY();
|
||||
this.stand.head[2] = (float) head.getZ();
|
||||
|
||||
EulerAngle body = stand.getBodyPose();
|
||||
this.stand.body[0] = (float) body.getX();
|
||||
this.stand.body[1] = (float) body.getY();
|
||||
this.stand.body[2] = (float) body.getZ();
|
||||
|
||||
EulerAngle leftLeg = stand.getLeftLegPose();
|
||||
this.stand.leftLeg[0] = (float) leftLeg.getX();
|
||||
this.stand.leftLeg[1] = (float) leftLeg.getY();
|
||||
this.stand.leftLeg[2] = (float) leftLeg.getZ();
|
||||
|
||||
EulerAngle rightLeg = stand.getRightLegPose();
|
||||
this.stand.rightLeg[0] = (float) rightLeg.getX();
|
||||
this.stand.rightLeg[1] = (float) rightLeg.getY();
|
||||
this.stand.rightLeg[2] = (float) rightLeg.getZ();
|
||||
|
||||
EulerAngle leftArm = stand.getLeftArmPose();
|
||||
this.stand.leftArm[0] = (float) leftArm.getX();
|
||||
this.stand.leftArm[1] = (float) leftArm.getY();
|
||||
this.stand.leftArm[2] = (float) leftArm.getZ();
|
||||
|
||||
EulerAngle rightArm = stand.getRightArmPose();
|
||||
this.stand.rightArm[0] = (float) rightArm.getX();
|
||||
this.stand.rightArm[1] = (float) rightArm.getY();
|
||||
this.stand.rightArm[2] = (float) rightArm.getZ();
|
||||
|
||||
if (stand.hasArms()) {
|
||||
this.stand.arms = true;
|
||||
}
|
||||
if (!stand.hasBasePlate()) {
|
||||
this.stand.noPlate = true;
|
||||
}
|
||||
if (!stand.isVisible()) {
|
||||
this.stand.invisible = true;
|
||||
}
|
||||
if (stand.isSmall()) {
|
||||
this.stand.small = true;
|
||||
}
|
||||
return;
|
||||
case "ENDERMITE":
|
||||
return;
|
||||
case "BAT":
|
||||
if (((Bat) entity).isAwake()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
return;
|
||||
case "ENDER_DRAGON":
|
||||
EnderDragon entity1 = (EnderDragon) entity;
|
||||
this.dataByte = (byte) entity1.getPhase().ordinal();
|
||||
return;
|
||||
case "SKELETON":
|
||||
case "WITHER_SKELETON":
|
||||
case "GUARDIAN":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "GHAST":
|
||||
case "MAGMA_CUBE":
|
||||
case "SQUID":
|
||||
case "PIG_ZOMBIE":
|
||||
case "HOGLIN":
|
||||
case "ZOMBIFIED_PIGLIN":
|
||||
case "PIGLIN":
|
||||
case "PIGLIN_BRUTE":
|
||||
case "ZOMBIE":
|
||||
case "WITHER":
|
||||
case "WITCH":
|
||||
case "SPIDER":
|
||||
case "CAVE_SPIDER":
|
||||
case "SILVERFISH":
|
||||
case "GIANT":
|
||||
case "ENDERMAN":
|
||||
case "CREEPER":
|
||||
case "BLAZE":
|
||||
case "SHULKER":
|
||||
case "SNOWMAN":
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case "IRON_GOLEM":
|
||||
if (((IronGolem) entity).isPlayerCreated()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
storeLiving((LivingEntity) entity);
|
||||
// END LIVING //
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.hash == obj.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
public void storeInventory(InventoryHolder held) {
|
||||
this.inventory = held.getInventory().getContents().clone();
|
||||
}
|
||||
|
||||
void restoreLiving(LivingEntity entity) {
|
||||
entity.setCanPickupItems(this.lived.loot);
|
||||
if (this.lived.name != null) {
|
||||
entity.setCustomName(this.lived.name);
|
||||
entity.setCustomNameVisible(this.lived.visible);
|
||||
}
|
||||
if (this.lived.potions != null && !this.lived.potions.isEmpty()) {
|
||||
entity.addPotionEffects(this.lived.potions);
|
||||
}
|
||||
entity.setRemainingAir(this.lived.air);
|
||||
entity.setRemoveWhenFarAway(this.lived.persistent);
|
||||
if (this.lived.equipped) {
|
||||
this.restoreEquipment(entity);
|
||||
}
|
||||
if (this.lived.leashed) {
|
||||
// TODO leashes
|
||||
// World world = entity.getWorld();
|
||||
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) +
|
||||
// lived.leashX, Math.floor(y) + lived.leashY, Math.floor(z) + lived.leashZ),
|
||||
// EntityType.LEASH_HITCH);
|
||||
// entity.setLeashHolder(leash);
|
||||
}
|
||||
}
|
||||
|
||||
void restoreEquipment(LivingEntity entity) {
|
||||
EntityEquipment equipment = entity.getEquipment();
|
||||
if (equipment != null) {
|
||||
equipment.setItemInMainHand(this.lived.mainHand);
|
||||
equipment.setItemInOffHand(this.lived.offHand);
|
||||
equipment.setHelmet(this.lived.helmet);
|
||||
equipment.setChestplate(this.lived.chestplate);
|
||||
equipment.setLeggings(this.lived.leggings);
|
||||
equipment.setBoots(this.lived.boots);
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreInventory(InventoryHolder entity) {
|
||||
try {
|
||||
entity.getInventory().setContents(this.inventory);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.error("Failed to restore inventory", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void storeLiving(LivingEntity lived) {
|
||||
this.lived = new LivingEntityStats();
|
||||
this.lived.potions = lived.getActivePotionEffects();
|
||||
this.lived.loot = lived.getCanPickupItems();
|
||||
this.lived.name = lived.getCustomName();
|
||||
this.lived.visible = lived.isCustomNameVisible();
|
||||
this.lived.health = (float) lived.getHealth();
|
||||
this.lived.air = (short) lived.getRemainingAir();
|
||||
this.lived.persistent = lived.getRemoveWhenFarAway();
|
||||
this.lived.leashed = lived.isLeashed();
|
||||
if (this.lived.leashed) {
|
||||
Location location = lived.getLeashHolder().getLocation();
|
||||
this.lived.leashX = (short) (this.getX() - location.getBlockX());
|
||||
this.lived.leashY = (short) (this.getY() - location.getBlockY());
|
||||
this.lived.leashZ = (short) (this.getZ() - location.getBlockZ());
|
||||
}
|
||||
EntityEquipment equipment = lived.getEquipment();
|
||||
this.lived.equipped = equipment != null;
|
||||
if (this.lived.equipped) {
|
||||
storeEquipment(equipment);
|
||||
}
|
||||
}
|
||||
|
||||
void storeEquipment(EntityEquipment equipment) {
|
||||
this.lived.mainHand = equipment.getItemInMainHand().clone();
|
||||
this.lived.offHand = equipment.getItemInOffHand().clone();
|
||||
this.lived.boots = equipment.getBoots().clone();
|
||||
this.lived.leggings = equipment.getLeggings().clone();
|
||||
this.lived.chestplate = equipment.getChestplate().clone();
|
||||
this.lived.helmet = equipment.getHelmet().clone();
|
||||
}
|
||||
|
||||
private void restoreTameable(Tameable entity) {
|
||||
if (this.tamed.tamed) {
|
||||
if (this.tamed.owner != null) {
|
||||
entity.setTamed(true);
|
||||
entity.setOwner(this.tamed.owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreAgeable(Ageable entity) {
|
||||
if (!this.aged.adult) {
|
||||
entity.setBaby();
|
||||
}
|
||||
entity.setAgeLock(this.aged.locked);
|
||||
if (this.aged.age > 0) {
|
||||
entity.setAge(this.aged.age);
|
||||
}
|
||||
}
|
||||
|
||||
public void storeAgeable(Ageable aged) {
|
||||
this.aged = new AgeableStats();
|
||||
this.aged.age = aged.getAge();
|
||||
this.aged.locked = aged.getAgeLock();
|
||||
this.aged.adult = aged.isAdult();
|
||||
}
|
||||
|
||||
public void storeTameable(Tameable tamed) {
|
||||
this.tamed = new TameableStats();
|
||||
this.tamed.owner = tamed.getOwner();
|
||||
this.tamed.tamed = tamed.isTamed();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // Paper deprecation
|
||||
@Override
|
||||
public Entity spawn(World world, int xOffset, int zOffset) {
|
||||
Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset);
|
||||
location.setYaw(this.yaw);
|
||||
location.setPitch(this.pitch);
|
||||
if (!this.getType().isSpawnable()) {
|
||||
return null;
|
||||
}
|
||||
Entity entity;
|
||||
switch (this.getType().toString()) {
|
||||
case "DROPPED_ITEM":
|
||||
return world.dropItem(location, this.stack);
|
||||
case "PLAYER":
|
||||
case "LEASH_HITCH":
|
||||
return null;
|
||||
case "ITEM_FRAME":
|
||||
entity = world.spawn(location, ItemFrame.class);
|
||||
break;
|
||||
case "PAINTING":
|
||||
entity = world.spawn(location, Painting.class);
|
||||
break;
|
||||
default:
|
||||
entity = world.spawnEntity(location, this.getType());
|
||||
break;
|
||||
}
|
||||
if (this.depth == 0) {
|
||||
return entity;
|
||||
}
|
||||
if (this.base.passenger != null) {
|
||||
try {
|
||||
entity.addPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (this.base.fall != 0) {
|
||||
entity.setFallDistance(this.base.fall);
|
||||
}
|
||||
if (this.base.fire != 0) {
|
||||
entity.setFireTicks(this.base.fire);
|
||||
}
|
||||
if (this.base.age != 0) {
|
||||
entity.setTicksLived(this.base.age);
|
||||
}
|
||||
entity.setVelocity(new Vector(this.base.vX, this.base.vY, this.base.vZ));
|
||||
if (this.depth == 1) {
|
||||
return entity;
|
||||
}
|
||||
if (this.noGravity) {
|
||||
entity.setGravity(false);
|
||||
}
|
||||
switch (entity.getType().toString()) {
|
||||
case "BOAT":
|
||||
Boat boat = (Boat) entity;
|
||||
boat.setWoodType(TreeSpecies.values()[dataByte]);
|
||||
return entity;
|
||||
case "SLIME":
|
||||
((Slime) entity).setSize(this.dataByte);
|
||||
return entity;
|
||||
case "ARROW":
|
||||
case "EGG":
|
||||
case "ENDER_CRYSTAL":
|
||||
case "ENDER_PEARL":
|
||||
case "ENDER_SIGNAL":
|
||||
case "DROPPED_ITEM":
|
||||
case "EXPERIENCE_ORB":
|
||||
case "FALLING_BLOCK":
|
||||
case "FIREBALL":
|
||||
case "FIREWORK":
|
||||
case "FISHING_HOOK":
|
||||
case "LEASH_HITCH":
|
||||
case "LIGHTNING":
|
||||
case "MINECART":
|
||||
case "MINECART_COMMAND":
|
||||
case "MINECART_MOB_SPAWNER":
|
||||
case "MINECART_TNT":
|
||||
case "PLAYER":
|
||||
case "PRIMED_TNT":
|
||||
case "SMALL_FIREBALL":
|
||||
case "SNOWBALL":
|
||||
case "SPLASH_POTION":
|
||||
case "THROWN_EXP_BOTTLE":
|
||||
case "SPECTRAL_ARROW":
|
||||
case "SHULKER_BULLET":
|
||||
case "AREA_EFFECT_CLOUD":
|
||||
case "DRAGON_FIREBALL":
|
||||
case "WITHER_SKULL":
|
||||
case "MINECART_FURNACE":
|
||||
case "LLAMA_SPIT":
|
||||
case "TRIDENT":
|
||||
case "UNKNOWN":
|
||||
// Do this stuff later
|
||||
return entity;
|
||||
// MISC //
|
||||
case "ITEM_FRAME":
|
||||
ItemFrame itemframe = (ItemFrame) entity;
|
||||
itemframe.setRotation(Rotation.values()[this.dataByte]);
|
||||
itemframe.setItem(this.stack);
|
||||
return entity;
|
||||
case "PAINTING":
|
||||
Painting painting = (Painting) entity;
|
||||
painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
|
||||
painting.setArt(Art.getByName(this.dataString), true);
|
||||
return entity;
|
||||
// END MISC //
|
||||
// INVENTORY HOLDER //
|
||||
case "MINECART_CHEST":
|
||||
case "MINECART_HOPPER":
|
||||
restoreInventory((InventoryHolder) entity);
|
||||
return entity;
|
||||
// START LIVING ENTITY //
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case "HORSE":
|
||||
case "LLAMA":
|
||||
case "SKELETON_HORSE":
|
||||
case "DONKEY":
|
||||
case "MULE":
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
horse.setJumpStrength(this.horse.jump);
|
||||
if (horse instanceof ChestedHorse) {
|
||||
((ChestedHorse) horse).setCarryingChest(this.horse.chest);
|
||||
}
|
||||
//todo broken as of 1.13
|
||||
//horse.setVariant(this.horse.variant);
|
||||
//horse.setStyle(this.horse.style);
|
||||
//horse.setColor(this.horse.color);
|
||||
restoreTameable(horse);
|
||||
restoreAgeable(horse);
|
||||
restoreLiving(horse);
|
||||
restoreInventory(horse);
|
||||
return entity;
|
||||
// END INVENTORY HOLDER //
|
||||
case "WOLF":
|
||||
case "OCELOT":
|
||||
restoreTameable((Tameable) entity);
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
// END AGEABLE //
|
||||
case "SHEEP":
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (this.dataByte == 1) {
|
||||
sheep.setSheared(true);
|
||||
}
|
||||
if (this.dataByte2 != 0) {
|
||||
sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
|
||||
}
|
||||
restoreAgeable(sheep);
|
||||
restoreLiving(sheep);
|
||||
return sheep;
|
||||
case "VILLAGER":
|
||||
case "CHICKEN":
|
||||
case "COW":
|
||||
case "TURTLE":
|
||||
case "POLAR_BEAR":
|
||||
case "MUSHROOM_COW":
|
||||
case "PIG":
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
// END AGEABLE //
|
||||
case "RABBIT":
|
||||
if (this.dataByte != 0) {
|
||||
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
|
||||
}
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case "ARMOR_STAND":
|
||||
// CHECK positions
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
if (this.inventory[0] != null) {
|
||||
stand.setItemInHand(this.inventory[0]);
|
||||
}
|
||||
if (this.inventory[1] != null) {
|
||||
stand.setHelmet(this.inventory[1]);
|
||||
}
|
||||
if (this.inventory[2] != null) {
|
||||
stand.setChestplate(this.inventory[2]);
|
||||
}
|
||||
if (this.inventory[3] != null) {
|
||||
stand.setLeggings(this.inventory[3]);
|
||||
}
|
||||
if (this.inventory[4] != null) {
|
||||
stand.setBoots(this.inventory[4]);
|
||||
}
|
||||
if (this.stand.head[0] != 0 || this.stand.head[1] != 0 || this.stand.head[2] != 0) {
|
||||
EulerAngle pose =
|
||||
new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
||||
stand.setHeadPose(pose);
|
||||
}
|
||||
if (this.stand.body[0] != 0 || this.stand.body[1] != 0 || this.stand.body[2] != 0) {
|
||||
EulerAngle pose =
|
||||
new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
||||
stand.setBodyPose(pose);
|
||||
}
|
||||
if (this.stand.leftLeg[0] != 0 || this.stand.leftLeg[1] != 0
|
||||
|| this.stand.leftLeg[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1],
|
||||
this.stand.leftLeg[2]
|
||||
);
|
||||
stand.setLeftLegPose(pose);
|
||||
}
|
||||
if (this.stand.rightLeg[0] != 0 || this.stand.rightLeg[1] != 0
|
||||
|| this.stand.rightLeg[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1],
|
||||
this.stand.rightLeg[2]
|
||||
);
|
||||
stand.setRightLegPose(pose);
|
||||
}
|
||||
if (this.stand.leftArm[0] != 0 || this.stand.leftArm[1] != 0
|
||||
|| this.stand.leftArm[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1],
|
||||
this.stand.leftArm[2]
|
||||
);
|
||||
stand.setLeftArmPose(pose);
|
||||
}
|
||||
if (this.stand.rightArm[0] != 0 || this.stand.rightArm[1] != 0
|
||||
|| this.stand.rightArm[2] != 0) {
|
||||
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1],
|
||||
this.stand.rightArm[2]
|
||||
);
|
||||
stand.setRightArmPose(pose);
|
||||
}
|
||||
if (this.stand.invisible) {
|
||||
stand.setVisible(false);
|
||||
}
|
||||
if (this.stand.arms) {
|
||||
stand.setArms(true);
|
||||
}
|
||||
if (this.stand.noPlate) {
|
||||
stand.setBasePlate(false);
|
||||
}
|
||||
if (this.stand.small) {
|
||||
stand.setSmall(true);
|
||||
}
|
||||
restoreLiving(stand);
|
||||
return stand;
|
||||
case "BAT":
|
||||
if (this.dataByte != 0) {
|
||||
((Bat) entity).setAwake(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case "ENDER_DRAGON":
|
||||
if (this.dataByte != 0) {
|
||||
((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case "ENDERMITE":
|
||||
case "GHAST":
|
||||
case "MAGMA_CUBE":
|
||||
case "SQUID":
|
||||
case "PIG_ZOMBIE":
|
||||
case "HOGLIN":
|
||||
case "PIGLIN":
|
||||
case "ZOMBIFIED_PIGLIN":
|
||||
case "PIGLIN_BRUTE":
|
||||
case "ZOMBIE":
|
||||
case "WITHER":
|
||||
case "WITCH":
|
||||
case "SPIDER":
|
||||
case "CAVE_SPIDER":
|
||||
case "SILVERFISH":
|
||||
case "GIANT":
|
||||
case "ENDERMAN":
|
||||
case "CREEPER":
|
||||
case "BLAZE":
|
||||
case "SNOWMAN":
|
||||
case "SHULKER":
|
||||
case "GUARDIAN":
|
||||
case "ELDER_GUARDIAN":
|
||||
case "SKELETON":
|
||||
case "WITHER_SKELETON":
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case "IRON_GOLEM":
|
||||
if (this.dataByte != 0) {
|
||||
((IronGolem) entity).setPlayerCreated(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
default:
|
||||
if (Settings.DEBUG) {
|
||||
LOGGER.info("Could not identify entity: {}", entity.getType());
|
||||
}
|
||||
return entity;
|
||||
// END LIVING
|
||||
}
|
||||
}
|
||||
|
||||
public void saveEntity() {
|
||||
}
|
||||
|
||||
private byte getOrdinal(Object[] list, Object value) {
|
||||
for (byte i = 0; i < list.length; i++) {
|
||||
if (list[i].equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
|
||||
class TameableStats {
|
||||
|
||||
AnimalTamer owner;
|
||||
boolean tamed;
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.entity;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class TeleportEntityWrapper extends EntityWrapper {
|
||||
|
||||
private Location oldLocation;
|
||||
private boolean gravityOld;
|
||||
private boolean invulnerableOld;
|
||||
private int fireTicksOld;
|
||||
private int livingTicksOld;
|
||||
|
||||
public TeleportEntityWrapper(final Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawn(final World world, final int xOffset, final int zOffset) {
|
||||
if (!getEntity().getLocation().getChunk().equals(oldLocation.getChunk())) {
|
||||
final Location oldLocation = this.oldLocation.clone();
|
||||
oldLocation.add(xOffset, 0, xOffset);
|
||||
getEntity().teleport(oldLocation);
|
||||
getEntity().setGravity(gravityOld);
|
||||
getEntity().setInvulnerable(invulnerableOld);
|
||||
getEntity().setFireTicks(fireTicksOld);
|
||||
getEntity().setTicksLived(livingTicksOld);
|
||||
getEntity().removeMetadata("ps-tmp-teleport", BukkitPlatform.getPlugin(BukkitPlatform.class));
|
||||
}
|
||||
return getEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEntity() {
|
||||
if (getEntity().hasMetadata("ps-tmp-teleport")) {
|
||||
this.oldLocation = (Location) this.getEntity().getMetadata("ps-tmp-teleport").get(0);
|
||||
} else {
|
||||
this.oldLocation = this.getEntity().getLocation();
|
||||
}
|
||||
|
||||
// To account for offsets in the chunk manager
|
||||
this.oldLocation = oldLocation.clone();
|
||||
this.oldLocation.setX(this.getX());
|
||||
this.oldLocation.setY(this.getY());
|
||||
this.oldLocation.setZ(this.getZ());
|
||||
|
||||
this.gravityOld = this.getEntity().hasGravity();
|
||||
this.getEntity().setGravity(false);
|
||||
this.invulnerableOld = this.getEntity().isInvulnerable();
|
||||
this.getEntity().setInvulnerable(true);
|
||||
this.fireTicksOld = this.getEntity().getFireTicks();
|
||||
this.livingTicksOld = this.getEntity().getTicksLived();
|
||||
this.getEntity().setMetadata(
|
||||
"ps-tmp-teleport",
|
||||
new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation)
|
||||
);
|
||||
final Chunk newChunk = getNewChunk();
|
||||
this.getEntity().teleport(
|
||||
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
|
||||
}
|
||||
|
||||
private Chunk getNewChunk() {
|
||||
final Chunk oldChunk = oldLocation.getChunk();
|
||||
Chunk chunk = null;
|
||||
|
||||
for (Chunk lChunk : oldChunk.getWorld().getLoadedChunks()) {
|
||||
if (!lChunk.equals(oldChunk) && lChunk.isLoaded()) {
|
||||
chunk = lChunk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chunk == null) {
|
||||
for (int dx = 1; dx < Integer.MAX_VALUE; dx++) {
|
||||
for (int dz = 0; dz < Integer.MAX_VALUE; dz++) {
|
||||
if ((chunk = getChunkRelative(oldChunk, dx, dz)).isLoaded()) {
|
||||
break;
|
||||
} else if ((chunk = getChunkRelative(oldChunk, -dx, dz)).isLoaded()) {
|
||||
break;
|
||||
} else if ((chunk = getChunkRelative(oldChunk, dx, -dz)).isLoaded()) {
|
||||
break;
|
||||
} else if ((chunk = getChunkRelative(oldChunk, -dx, -dz)).isLoaded()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private Chunk getChunkRelative(final Chunk chunk, final int dx, final int dz) {
|
||||
return chunk.getWorld().getChunkAt(chunk.getX() + dx, chunk.getZ() + dz);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
|
||||
/**
|
||||
* Called when a flag is removed from a plot
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final PlotCluster cluster;
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param cluster PlotCluster from which the flag was removed
|
||||
*/
|
||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster involved
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
public PlotCluster getCluster() {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
private final boolean auto;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||
*
|
||||
* @param player Player that claimed the plot
|
||||
* @param plot Plot that was claimed
|
||||
*/
|
||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
this.auto = auto;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if it was an automated claim, else false
|
||||
*/
|
||||
public boolean wasAuto() {
|
||||
return auto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that entered the plot
|
||||
* @param plot Plot that was entered
|
||||
*/
|
||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Plot plot;
|
||||
|
||||
/**
|
||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||
*
|
||||
* @param player Player that left the plot
|
||||
* @param plot Plot that was left
|
||||
*/
|
||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
||||
super(player);
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was denied/un-denied
|
||||
* @param added true of add to deny list, false if removed
|
||||
*/
|
||||
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the helper list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Player initiator;
|
||||
private final boolean added;
|
||||
private final UUID player;
|
||||
|
||||
/**
|
||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||
*
|
||||
* @param initiator Player that initiated the event
|
||||
* @param plot Plot in which the event occurred
|
||||
* @param player Player that was added/removed from the trusted list
|
||||
* @param added true of the player was added, false if the player was removed
|
||||
*/
|
||||
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
super(plot);
|
||||
this.initiator = initiator;
|
||||
this.added = added;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player was added
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID added/removed
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player initiating the action
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getInitiator() {
|
||||
return initiator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a player teleports to a plot
|
||||
*
|
||||
*/
|
||||
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Location from;
|
||||
private final Plot plot;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
||||
*
|
||||
* @param player That was teleported
|
||||
* @param from Start location
|
||||
* @param plot Plot to which the player was teleported
|
||||
*/
|
||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
|
||||
super(player);
|
||||
this.from = from;
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the from location
|
||||
*
|
||||
* @return Location
|
||||
*/
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot involved
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* Called when a plot is cleared
|
||||
*
|
||||
*/
|
||||
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||
public PlotClearEvent(Plot plot) {
|
||||
super(plot);
|
||||
}
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return getPlot().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return getPlot().getArea().worldname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
* Called when a plot is deleted
|
||||
*
|
||||
*/
|
||||
public class PlotDeleteEvent extends PlotEvent {
|
||||
public PlotDeleteEvent(Plot plot) {
|
||||
super(plot);
|
||||
}
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlotId
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public PlotId getPlotId() {
|
||||
return getPlot().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getWorld() {
|
||||
return getPlot().getArea().worldname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
public abstract class PlotEvent extends Event {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
public PlotEvent(final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public final Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a Flag is added to a plot
|
||||
*
|
||||
*/
|
||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
||||
*
|
||||
* @param flag Flag that was added
|
||||
* @param plot Plot to which the flag was added
|
||||
*/
|
||||
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
|
||||
/**
|
||||
* Called when a flag is removed from a plot
|
||||
*
|
||||
*/
|
||||
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param plot Plot from which the flag was removed
|
||||
*/
|
||||
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
|
||||
super(plot);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlotMergeEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final ArrayList<PlotId> plots;
|
||||
private boolean cancelled;
|
||||
private Plot plot;
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* PlotMergeEvent: Called when plots are merged
|
||||
*
|
||||
* @param world World in which the event occurred
|
||||
* @param plot Plot that was merged
|
||||
* @param plots A list of plots involved in the event
|
||||
*/
|
||||
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) {
|
||||
this.plots = plots;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added;
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main plot
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public Plot getPlot() {
|
||||
return plot;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
|
||||
/**
|
||||
* Created 2015-07-13 for PlotSquaredGit
|
||||
*
|
||||
*/
|
||||
public class PlotRateEvent extends PlotEvent {
|
||||
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final PlotPlayer rater;
|
||||
private Rating rating;
|
||||
|
||||
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
|
||||
super(plot);
|
||||
this.rater = rater;
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlotPlayer getRater() {
|
||||
return rater;
|
||||
}
|
||||
|
||||
public void setRating(final Rating rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public Rating getRating() {
|
||||
return rating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PlotUnlinkEvent extends Event implements Cancellable {
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
private final ArrayList<PlotId> plots;
|
||||
private final World world;
|
||||
private boolean cancelled;
|
||||
private final PlotArea area;
|
||||
|
||||
/**
|
||||
* Called when a mega-plot is unlinked.
|
||||
*
|
||||
* @param world World in which the event occurred
|
||||
* @param plots Plots that are involved in the event
|
||||
*/
|
||||
public PlotUnlinkEvent(final World world, PlotArea area, final ArrayList<PlotId> plots) {
|
||||
this.plots = plots;
|
||||
this.world = world;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots involved
|
||||
*
|
||||
* @return PlotId
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public PlotArea getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.bukkit.queue.LimitedRegionWrapperQueue;
|
||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.UncheckedWorldLocation;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.LimitedRegion;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
final class BlockStatePopulator extends BlockPopulator {
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
|
||||
/**
|
||||
* @since 6.9.0
|
||||
*/
|
||||
public BlockStatePopulator(
|
||||
final @NonNull IndependentPlotGenerator plotGenerator
|
||||
) {
|
||||
this.plotGenerator = plotGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link BlockStatePopulator#BlockStatePopulator(IndependentPlotGenerator)} as plotAreManager is unused
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "6.9.0")
|
||||
public BlockStatePopulator(
|
||||
final @NonNull IndependentPlotGenerator plotGenerator,
|
||||
final @NonNull PlotAreaManager plotAreaManager
|
||||
) {
|
||||
this.plotGenerator = plotGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(
|
||||
@NonNull final WorldInfo worldInfo,
|
||||
@NonNull final Random random,
|
||||
final int chunkX,
|
||||
final int chunkZ,
|
||||
@NonNull final LimitedRegion limitedRegion
|
||||
) {
|
||||
PlotArea area = UncheckedWorldLocation.at(worldInfo.getName(), chunkX << 4, 0, chunkZ << 4).getPlotArea();
|
||||
if (area == null || (area instanceof HybridPlotWorld hpw && !hpw.populationNeeded()) || area instanceof SinglePlotArea) {
|
||||
return;
|
||||
}
|
||||
LimitedRegionWrapperQueue wrapped = new LimitedRegionWrapperQueue(limitedRegion);
|
||||
// It is possible for the region to be larger than the chunk, but there is no reason for P2 to need to populate
|
||||
// outside of the actual chunk area.
|
||||
Location min = UncheckedWorldLocation.at(worldInfo.getName(), chunkX << 4, worldInfo.getMinHeight(), chunkZ << 4);
|
||||
Location max = UncheckedWorldLocation.at(
|
||||
worldInfo.getName(),
|
||||
(chunkX << 4) + 15,
|
||||
worldInfo.getMaxHeight(),
|
||||
(chunkZ << 4) + 15
|
||||
);
|
||||
ScopedQueueCoordinator offsetChunkQueue = new ScopedQueueCoordinator(wrapped, min, max);
|
||||
this.plotGenerator.populateChunk(offsetChunkQueue, area);
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,17 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
|
||||
|
||||
private static BukkitAugmentedGenerator generator;
|
||||
|
||||
private BukkitAugmentedGenerator() {}
|
||||
|
||||
public static BukkitAugmentedGenerator get(World world) {
|
||||
for (BlockPopulator populator : world.getPopulators()) {
|
||||
@ -48,15 +27,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) {
|
||||
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(BukkitAdapter.adapt(world));
|
||||
// The chunk is already loaded and we do not want to load the chunk in "fully" by using any PaperLib methods.
|
||||
queue.setForceSync(true);
|
||||
queue.setSideEffectSet(SideEffectSet.none());
|
||||
queue.setBiomesEnabled(false);
|
||||
queue.setChunkObject(source);
|
||||
AugmentedUtils.generateChunk(world.getName(), source.getX(), source.getZ(), queue);
|
||||
queue.enqueue();
|
||||
public void populate(final World world, Random r, final Chunk chunk) {
|
||||
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.bukkit.queue.GenChunk;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitWorld;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.generator.SingleWorldGenerator;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.plotsquared.bukkit.util.block.GenChunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -43,244 +43,288 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper<ChunkGenerator> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final boolean PAPER_ASYNC_SAFE = true;
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
private final PlotChunk<Chunk> chunkSetter;
|
||||
private final PseudoRandom random = new PseudoRandom();
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final ChunkGenerator platformGenerator;
|
||||
private final boolean full;
|
||||
private final String levelName;
|
||||
private List<BlockPopulator> populators;
|
||||
private final List<BlockPopulator> populators = new ArrayList<>();
|
||||
private boolean loaded = false;
|
||||
private ChunkGenerator platformGenerator;
|
||||
private boolean full;
|
||||
|
||||
public BukkitPlotGenerator(
|
||||
final @NonNull String name,
|
||||
final @NonNull IndependentPlotGenerator generator,
|
||||
final @NonNull PlotAreaManager plotAreaManager
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.levelName = name;
|
||||
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
||||
this.plotGenerator = generator;
|
||||
this.platformGenerator = this;
|
||||
this.populators = new ArrayList<>();
|
||||
int minecraftMinorVersion = PlotSquared.platform().serverVersion()[1];
|
||||
if (minecraftMinorVersion >= 17) {
|
||||
this.populators.add(new BlockStatePopulator(this.plotGenerator));
|
||||
} else {
|
||||
this.populators.add(new LegacyBlockStatePopulator(this.plotGenerator));
|
||||
}
|
||||
this.full = true;
|
||||
}
|
||||
|
||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, final @NonNull PlotAreaManager plotAreaManager) {
|
||||
if (cg instanceof BukkitPlotGenerator) {
|
||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
||||
+ " is already a BukkitPlotGenerator!");
|
||||
}
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.levelName = world;
|
||||
this.full = false;
|
||||
this.platformGenerator = cg;
|
||||
this.plotGenerator = new DelegatePlotGenerator(cg, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void augment(PlotArea area) {
|
||||
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.getWorldName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return this.full;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndependentPlotGenerator getPlotGenerator() {
|
||||
return this.plotGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getPlatformGenerator() {
|
||||
return this.platformGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<BlockPopulator> getDefaultPopulators(@NonNull World world) {
|
||||
try {
|
||||
checkLoaded(world);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ArrayList<BlockPopulator> toAdd = new ArrayList<>();
|
||||
List<BlockPopulator> existing = world.getPopulators();
|
||||
if (populators == null && platformGenerator != null) {
|
||||
populators = new ArrayList<>(platformGenerator.getDefaultPopulators(world));
|
||||
}
|
||||
if (populators != null) {
|
||||
for (BlockPopulator populator : this.populators) {
|
||||
if (!existing.contains(populator)) {
|
||||
toAdd.add(populator);
|
||||
populators.add(new BlockPopulator() {
|
||||
@Override
|
||||
public void populate(World world, Random r, Chunk c) {
|
||||
if (!(chunkSetter instanceof GenChunk)) {
|
||||
PS.debug("Current PlotChunk is not relevant to population?");
|
||||
PS.stacktrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
private synchronized void checkLoaded(@NonNull World world) {
|
||||
// Do not attempt to load configurations until WorldEdit has a platform ready.
|
||||
if (!PlotSquared.get().isWeInitialised()) {
|
||||
return;
|
||||
}
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
PlotSquared.get().loadWorld(name, this);
|
||||
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(name);
|
||||
if (!areas.isEmpty()) {
|
||||
PlotArea area = areas.iterator().next();
|
||||
if (!area.isMobSpawning()) {
|
||||
if (!area.isSpawnEggs()) {
|
||||
world.setSpawnFlags(false, false);
|
||||
}
|
||||
setSpawnLimits(world, 0);
|
||||
} else {
|
||||
world.setSpawnFlags(true, true);
|
||||
setSpawnLimits(world, -1);
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void setSpawnLimits(@NonNull World world, int limit) {
|
||||
world.setAmbientSpawnLimit(limit);
|
||||
world.setAnimalSpawnLimit(limit);
|
||||
world.setMonsterSpawnLimit(limit);
|
||||
world.setWaterAnimalSpawnLimit(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* The entire method is deprecated, but kept for compatibility with versions lower than or equal to 1.16.2.
|
||||
* The method will be removed in future versions, because WorldEdit and FastAsyncWorldEdit only support the latest point
|
||||
* release.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "6.11.0")
|
||||
@Override
|
||||
public @NonNull ChunkData generateChunkData(
|
||||
@NonNull World world, @NonNull Random random, int x, int z,
|
||||
@NonNull BiomeGrid biome
|
||||
) {
|
||||
int minY = BukkitWorld.getMinWorldHeight(world);
|
||||
int maxY = BukkitWorld.getMaxWorldHeight(world);
|
||||
GenChunk result = new GenChunk(minY, maxY);
|
||||
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
||||
if (result.getChunkData() != null) {
|
||||
for (int chunkX = 0; chunkX < 16; chunkX++) {
|
||||
for (int chunkZ = 0; chunkZ < 16; chunkZ++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
biome.setBiome(chunkX, y, chunkZ, Biome.PLAINS);
|
||||
|
||||
GenChunk result = (GenChunk) chunkSetter;
|
||||
if (result.result_data != null) {
|
||||
for (int i = 0; i < result.result_data.length; i++) {
|
||||
byte[] section = result.result_data[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < section.length; j++) {
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
c.getBlock(x, y, z).setData(section[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.getChunkData();
|
||||
}
|
||||
});
|
||||
chunkSetter = new GenChunk(null, null);
|
||||
this.full = true;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
||||
if (cg instanceof BukkitPlotGenerator) {
|
||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!");
|
||||
}
|
||||
// Set the chunk location
|
||||
result.setChunk(new ChunkWrapper(world.getName(), x, z));
|
||||
// Set the result data
|
||||
result.setChunkData(createChunkData(world));
|
||||
result.biomeGrid = biome;
|
||||
result.result = null;
|
||||
this.full = false;
|
||||
PS.get().debug("BukkitPlotGenerator does not fully support: " + cg);
|
||||
platformGenerator = cg;
|
||||
plotGenerator = new IndependentPlotGenerator() {
|
||||
@Override
|
||||
public void processSetup(SetupObject setup) {}
|
||||
|
||||
@Override
|
||||
public void initialize(PlotArea area) {}
|
||||
|
||||
@Override
|
||||
public PlotManager getNewPlotManager() {
|
||||
return new HybridGen().getNewPlotManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return cg.getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||
return new HybridGen().getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(final PlotChunk<?> result, final PlotArea settings, final PseudoRandom random) {
|
||||
World w = BukkitUtil.getWorld(world);
|
||||
Random r = new Random(result.getChunkWrapper().hashCode());
|
||||
BiomeGrid grid = new BiomeGrid() {
|
||||
@Override
|
||||
public void setBiome(int x, int z, Biome biome) {
|
||||
result.setBiome(x, z, biome.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
};
|
||||
try {
|
||||
// ChunkData will spill a bit
|
||||
ChunkData data = cg.generateChunkData(w, r, result.getX(), result.getZ(), grid);
|
||||
if (data != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {}
|
||||
// Populator spillage
|
||||
short[][] tmp = cg.generateExtBlockSections(w, r, result.getX(), result.getZ(), grid);
|
||||
if (tmp != null) {
|
||||
for (int i = 0; i < tmp.length; i++) {
|
||||
short[] section = tmp[i];
|
||||
if (section == null) {
|
||||
if (i < 7) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = i << 4; y < (i << 4) + 16; y++) {
|
||||
result.setBlock(x, y, z, (short) 0, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < section.length; j++) {
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
result.setBlock(x, y, z, section[j], (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BlockPopulator populator : cg.getDefaultPopulators(w)) {
|
||||
populator.populate(w, r, (Chunk) result.getChunk());
|
||||
}
|
||||
}
|
||||
};
|
||||
chunkSetter = new GenChunk(null, SetQueue.IMP.new ChunkWrapper(world, 0, 0));
|
||||
if (cg != null) {
|
||||
populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world)));
|
||||
}
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void augment(PlotArea area) {
|
||||
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.worldname));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return full;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndependentPlotGenerator getPlotGenerator() {
|
||||
return plotGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getPlatformGenerator() {
|
||||
return platformGenerator;
|
||||
}
|
||||
|
||||
// Catch any exceptions (as exceptions usually thrown)
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
||||
try {
|
||||
if (!loaded) {
|
||||
final String name = world.getName();
|
||||
PS.get().loadWorld(name, this);
|
||||
Set<PlotArea> areas = PS.get().getPlotAreas(name);
|
||||
if (!areas.isEmpty()) {
|
||||
PlotArea area = areas.iterator().next();
|
||||
if (!area.MOB_SPAWNING) {
|
||||
if (!area.SPAWN_EGGS) {
|
||||
world.setSpawnFlags(false, false);
|
||||
}
|
||||
world.setAmbientSpawnLimit(0);
|
||||
world.setAnimalSpawnLimit(0);
|
||||
world.setMonsterSpawnLimit(0);
|
||||
world.setWaterAnimalSpawnLimit(0);
|
||||
} else {
|
||||
world.setSpawnFlags(true, true);
|
||||
world.setAmbientSpawnLimit(-1);
|
||||
world.setAnimalSpawnLimit(-1);
|
||||
world.setMonsterSpawnLimit(-1);
|
||||
world.setWaterAnimalSpawnLimit(-1);
|
||||
}
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return populators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
|
||||
if (!(chunkSetter instanceof GenChunk)) {
|
||||
PS.debug("Current PlotChunk is not relevant to generation?");
|
||||
PS.stacktrace();
|
||||
return null;
|
||||
}
|
||||
GenChunk result = (GenChunk) chunkSetter;
|
||||
// Set the chunk location
|
||||
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
||||
// Set the result data
|
||||
result.cd = createChunkData(world);
|
||||
result.grid = grid;
|
||||
// Catch any exceptions (as exceptions usually thrown
|
||||
try {
|
||||
// Fill the result data if necessary
|
||||
if (this.platformGenerator != this) {
|
||||
return this.platformGenerator.generateChunkData(world, random, x, z, biome);
|
||||
if (platformGenerator != this) {
|
||||
return platformGenerator.generateChunkData(world, random, cx, cz, grid);
|
||||
} else {
|
||||
generate(BlockVector2.at(x, z), world, result);
|
||||
generate(world, cx, cz, result);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Return the result data
|
||||
return result.getChunkData();
|
||||
return result.cd;
|
||||
}
|
||||
|
||||
private void generate(BlockVector2 loc, World world, ScopedQueueCoordinator result) {
|
||||
|
||||
public void generate(World world, int cx, int cz, GenChunk result) {
|
||||
// Load if improperly loaded
|
||||
if (!this.loaded) {
|
||||
checkLoaded(world);
|
||||
if (!loaded) {
|
||||
final String name = world.getName();
|
||||
PS.get().loadWorld(name, this);
|
||||
loaded = true;
|
||||
}
|
||||
// Set random seed
|
||||
this.random.state = (cx << 16) | (cz & 0xFFFF);
|
||||
// Process the chunk
|
||||
if (ChunkManager.preProcessChunk(loc, result)) {
|
||||
result.modified = false;
|
||||
ChunkManager.preProcessChunk(result);
|
||||
if (result.modified) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
|
||||
if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
|
||||
+ ", world: " + world);
|
||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
||||
plotGenerator.generateChunk(chunkSetter, area, this.random);
|
||||
ChunkManager.postProcessChunk(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid grid) {
|
||||
if (!(chunkSetter instanceof GenChunk)) {
|
||||
PS.stacktrace();
|
||||
return new short[16][];
|
||||
}
|
||||
GenChunk result = (GenChunk) chunkSetter;
|
||||
// Set the chunk location
|
||||
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
||||
// Set the result data
|
||||
result.result = new short[16][];
|
||||
result.result_data = new byte[16][];
|
||||
result.grid = grid;
|
||||
// Catch any exceptions (as exceptions usually thrown
|
||||
try {
|
||||
this.plotGenerator.generateChunk(result, area);
|
||||
// Fill the result data
|
||||
if (platformGenerator != this) {
|
||||
return platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
|
||||
} else {
|
||||
generate(world, cx, cz, result);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// Recover from generator error
|
||||
e.printStackTrace();
|
||||
}
|
||||
ChunkManager.postProcessChunk(loc, result);
|
||||
// Return the result data
|
||||
return result.result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow spawning everywhere
|
||||
*/
|
||||
@Override
|
||||
public boolean canSpawn(final @NonNull World world, final int x, final int z) {
|
||||
public boolean canSpawn(final World world, final int x, final int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateCaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isParallelCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateMobs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.platformGenerator == this) {
|
||||
return this.plotGenerator.getName();
|
||||
}
|
||||
if (this.platformGenerator == null) {
|
||||
return "null";
|
||||
} else {
|
||||
return this.platformGenerator.getClass().getName();
|
||||
if (platformGenerator == this) {
|
||||
return "" + plotGenerator;
|
||||
}
|
||||
return platformGenerator == null ? "null" : platformGenerator.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
return toString().equals(obj.toString()) || toString().equals(obj.getClass().getName());
|
||||
return (toString().equals(obj.toString()) || toString().equals(obj.getClass().getName()));
|
||||
}
|
||||
|
||||
public String getLevelName() {
|
||||
return this.levelName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final String world;
|
||||
|
||||
public DelegatePlotGenerator(ChunkGenerator chunkGenerator, String world) {
|
||||
this.chunkGenerator = chunkGenerator;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PlotArea area) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.chunkGenerator.getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||
return PlotSquared.platform().defaultGenerator().getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(final ScopedQueueCoordinator result, PlotArea settings) {
|
||||
World world = BukkitUtil.getWorld(this.world);
|
||||
Location min = result.getMin();
|
||||
int chunkX = min.getX() >> 4;
|
||||
int chunkZ = min.getZ() >> 4;
|
||||
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
|
||||
try {
|
||||
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
||||
@Override
|
||||
public void setBiome(int x, int z, @NonNull Biome biome) {
|
||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||
}
|
||||
|
||||
//do not annotate with Override until we discontinue support for 1.4.4 (we no longer support 1.4.4)
|
||||
@Override
|
||||
public void setBiome(int x, int y, int z, @NonNull Biome biome) {
|
||||
result.setBiome(x, z, BukkitAdapter.adapt(biome));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Biome getBiome(int x, int z) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Biome getBiome(int x, int y, int z) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
};
|
||||
chunkGenerator.generateChunkData(world, random, chunkX, chunkZ, grid);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
for (BlockPopulator populator : chunkGenerator.getDefaultPopulators(world)) {
|
||||
populator.populate(world, random, world.getChunkAt(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.UncheckedWorldLocation;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
final class LegacyBlockStatePopulator extends BlockPopulator {
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
|
||||
/**
|
||||
* @since 6.9.0
|
||||
*/
|
||||
public LegacyBlockStatePopulator(
|
||||
final @NonNull IndependentPlotGenerator plotGenerator
|
||||
) {
|
||||
this.plotGenerator = plotGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NonNull final World world, @NonNull final Random random, @NonNull final Chunk source) {
|
||||
int chunkMinX = source.getX() << 4;
|
||||
int chunkMinZ = source.getZ() << 4;
|
||||
PlotArea area = Location.at(world.getName(), chunkMinX, 0, chunkMinZ).getPlotArea();
|
||||
if (area == null || (area instanceof HybridPlotWorld hpw && !hpw.populationNeeded()) || area instanceof SinglePlotArea) {
|
||||
return;
|
||||
}
|
||||
|
||||
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(new BukkitWorld(world));
|
||||
queue.setForceSync(true);
|
||||
queue.setSideEffectSet(SideEffectSet.none());
|
||||
queue.setBiomesEnabled(false);
|
||||
queue.setChunkObject(source);
|
||||
Location min = UncheckedWorldLocation.at(world.getName(), chunkMinX, world.getMinHeight(), chunkMinZ);
|
||||
Location max = UncheckedWorldLocation.at(world.getName(), chunkMinX + 15, world.getMaxHeight(), chunkMinZ + 15);
|
||||
ScopedQueueCoordinator offsetChunkQueue = new ScopedQueueCoordinator(queue, min, max);
|
||||
this.plotGenerator.populateChunk(offsetChunkQueue, area);
|
||||
queue.enqueue();
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.inject;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.plotsquared.core.backup.BackupManager;
|
||||
import com.plotsquared.core.backup.BackupProfile;
|
||||
import com.plotsquared.core.backup.NullBackupManager;
|
||||
import com.plotsquared.core.backup.PlayerBackupProfile;
|
||||
import com.plotsquared.core.backup.SimpleBackupManager;
|
||||
import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class BackupModule extends AbstractModule {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + BackupModule.class.getSimpleName());
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
try {
|
||||
install(new FactoryModuleBuilder()
|
||||
.implement(BackupProfile.class, PlayerBackupProfile.class).build(PlayerBackupProfileFactory.class));
|
||||
bind(BackupManager.class).to(SimpleBackupManager.class);
|
||||
} catch (final Exception e) {
|
||||
LOGGER.error("Failed to initialize backup manager", e);
|
||||
LOGGER.error("Backup features will be disabled");
|
||||
bind(BackupManager.class).to(NullBackupManager.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.inject;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.queue.BukkitChunkCoordinator;
|
||||
import com.plotsquared.bukkit.queue.BukkitQueueCoordinator;
|
||||
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitRegionManager;
|
||||
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.fawe.FaweRegionManager;
|
||||
import com.plotsquared.bukkit.util.fawe.FaweSchematicHandler;
|
||||
import com.plotsquared.core.PlotPlatform;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.generator.HybridGen;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
import com.plotsquared.core.inject.annotations.ConsoleActor;
|
||||
import com.plotsquared.core.inject.annotations.DefaultGenerator;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueProvider;
|
||||
import com.plotsquared.core.queue.subscriber.DefaultProgressSubscriber;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class BukkitModule extends AbstractModule {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + BukkitModule.class.getSimpleName());
|
||||
|
||||
private final BukkitPlatform bukkitPlatform;
|
||||
|
||||
public BukkitModule(final @NonNull BukkitPlatform bukkitPlatform) {
|
||||
this.bukkitPlatform = bukkitPlatform;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(PlayerManager.class).to(BukkitPlayerManager.class);
|
||||
bind(JavaPlugin.class).toInstance(bukkitPlatform);
|
||||
bind(PlotPlatform.class).toInstance(bukkitPlatform);
|
||||
bind(BukkitPlatform.class).toInstance(bukkitPlatform);
|
||||
bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class);
|
||||
// Console actor
|
||||
@NonNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
||||
bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
|
||||
bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
|
||||
bind(SetupUtils.class).to(BukkitSetupUtils.class);
|
||||
bind(WorldUtil.class).to(BukkitUtil.class);
|
||||
install(new FactoryModuleBuilder()
|
||||
.implement(ProgressSubscriber.class, DefaultProgressSubscriber.class)
|
||||
.build(ProgressSubscriberFactory.class));
|
||||
bind(ChunkManager.class).to(BukkitChunkManager.class);
|
||||
if (PlotSquared.platform().isFaweHooking()) {
|
||||
bind(SchematicHandler.class).to(FaweSchematicHandler.class);
|
||||
bind(RegionManager.class).to(FaweRegionManager.class);
|
||||
} else {
|
||||
bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
|
||||
bind(RegionManager.class).to(BukkitRegionManager.class);
|
||||
}
|
||||
bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class)));
|
||||
if (Settings.Enabled_Components.WORLDS) {
|
||||
bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
|
||||
try {
|
||||
bind(SingleWorldListener.class).toInstance(new SingleWorldListener());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
|
||||
}
|
||||
install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
|
||||
install(new FactoryModuleBuilder()
|
||||
.implement(ChunkCoordinator.class, BukkitChunkCoordinator.class)
|
||||
.build(ChunkCoordinatorFactory.class));
|
||||
install(new FactoryModuleBuilder().build(ChunkCoordinatorBuilderFactory.class));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@NonNull EconHandler provideEconHandler() {
|
||||
if (!Settings.Enabled_Components.ECONOMY) {
|
||||
return EconHandler.nullEconHandler();
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
try {
|
||||
BukkitEconHandler econHandler = new BukkitEconHandler();
|
||||
if (!econHandler.init()) {
|
||||
LOGGER.warn("Economy is enabled but no plugin is providing an economy service. Falling back...");
|
||||
return EconHandler.nullEconHandler();
|
||||
}
|
||||
return econHandler;
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
return EconHandler.nullEconHandler();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.inject;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.permissions.BukkitPermissionHandler;
|
||||
import com.plotsquared.bukkit.permissions.VaultPermissionHandler;
|
||||
import com.plotsquared.core.permissions.PermissionHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class PermissionModule extends AbstractModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PermissionHandler providePermissionHandler() {
|
||||
try {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
|
||||
return new VaultPermissionHandler();
|
||||
}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
return new BukkitPermissionHandler();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.inject;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.managers.BukkitWorldManager;
|
||||
import com.plotsquared.bukkit.managers.MultiverseWorldManager;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class WorldManagerModule extends AbstractModule {
|
||||
|
||||
@SuppressWarnings("removal") // Internal use only
|
||||
@Provides
|
||||
@Singleton
|
||||
PlatformWorldManager<World> provideWorldManager() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) {
|
||||
return new MultiverseWorldManager();
|
||||
} else {
|
||||
return new BukkitWorldManager();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,189 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.CopperOxideFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockFertilizeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockReceiveGameEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BlockEventListener117 implements Listener {
|
||||
|
||||
private static final Set<Material> COPPER_OXIDIZING = Set.of(
|
||||
Material.COPPER_BLOCK,
|
||||
Material.EXPOSED_COPPER,
|
||||
Material.WEATHERED_COPPER,
|
||||
Material.OXIDIZED_COPPER,
|
||||
Material.CUT_COPPER,
|
||||
Material.EXPOSED_CUT_COPPER,
|
||||
Material.WEATHERED_CUT_COPPER,
|
||||
Material.OXIDIZED_CUT_COPPER,
|
||||
Material.CUT_COPPER_STAIRS,
|
||||
Material.EXPOSED_CUT_COPPER_STAIRS,
|
||||
Material.WEATHERED_CUT_COPPER_STAIRS,
|
||||
Material.OXIDIZED_CUT_COPPER_STAIRS,
|
||||
Material.CUT_COPPER_SLAB,
|
||||
Material.EXPOSED_CUT_COPPER_SLAB,
|
||||
Material.WEATHERED_CUT_COPPER_SLAB,
|
||||
Material.OXIDIZED_CUT_COPPER_SLAB
|
||||
);
|
||||
|
||||
@Inject
|
||||
public BlockEventListener117() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockReceiveGame(BlockReceiveGameEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitPlayer plotPlayer = null;
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
plotPlayer = BukkitUtil.adapt(player);
|
||||
if (area.notifyIfOutsideBuildArea(plotPlayer, location.getY())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null && !PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, MiscInteractFlag.class, true) || plot != null && !plot.getFlag(
|
||||
MiscInteractFlag.class)) {
|
||||
if (plotPlayer != null) {
|
||||
if (plot != null) {
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
plot.debug(plotPlayer.getName() + " couldn't trigger sculk sensors because misc-interact = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Item item) {
|
||||
UUID itemThrower = item.getThrower();
|
||||
if (plot != null) {
|
||||
if (itemThrower == null && (itemThrower = item.getOwner()) == null) {
|
||||
plot.debug(
|
||||
"A thrown item couldn't trigger sculk sensors because misc-interact = false and the item's owner could not be resolved.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!plot.isAdded(itemThrower)) {
|
||||
if (!plot.isAdded(itemThrower)) {
|
||||
plot.debug("A thrown item couldn't trigger sculk sensors because misc-interact = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFertilize(BlockFertilizeEvent event) {
|
||||
Block block = event.getBlock();
|
||||
List<org.bukkit.block.BlockState> blocks = event.getBlocks();
|
||||
Location location = BukkitUtil.adapt(blocks.get(0).getLocation());
|
||||
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
Location blockLocation = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
blockLocation = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
if (blockLocation.isPlotArea()) {
|
||||
blocks.remove(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Plot origin = area.getOwnedPlot(location);
|
||||
if (origin == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
Location blockLocation = BukkitUtil.adapt(blocks.get(i).getLocation());
|
||||
if (!area.contains(blockLocation.getX(), blockLocation.getZ())) {
|
||||
blocks.remove(i);
|
||||
continue;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(blockLocation);
|
||||
if (!Objects.equals(plot, origin)) {
|
||||
event.getBlocks().remove(i);
|
||||
continue;
|
||||
}
|
||||
if (!area.buildRangeContainsY(location.getY())) {
|
||||
event.getBlocks().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
if (location.isPlotRoad()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (COPPER_OXIDIZING.contains(event.getNewState().getType())) {
|
||||
if (!plot.getFlag(CopperOxideFlag.class)) {
|
||||
plot.debug("Copper could not oxide because copper-oxide = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,365 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefClass;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefField;
|
||||
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
|
||||
import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ChunkListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final int version;
|
||||
|
||||
private RefMethod methodGetHandleChunk;
|
||||
private RefMethod methodGetHandleWorld;
|
||||
private RefField mustSave;
|
||||
/*
|
||||
private RefMethod methodGetFullChunk;
|
||||
private RefMethod methodGetBukkitChunk;
|
||||
private RefMethod methodGetChunkProvider;
|
||||
private RefMethod methodGetVisibleMap;
|
||||
private RefField worldServer;
|
||||
private RefField playerChunkMap;
|
||||
private RefField updatingChunks;
|
||||
private RefField visibleChunks;
|
||||
*/
|
||||
private Chunk lastChunk;
|
||||
private boolean ignoreUnload = false;
|
||||
private boolean isTrueForNotSave = true;
|
||||
|
||||
@Inject
|
||||
public ChunkListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
version = PlotSquared.platform().serverVersion()[1];
|
||||
if (!Settings.Chunk_Processor.AUTO_TRIM) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||
this.methodGetHandleWorld = classCraftWorld.getMethod("getHandle");
|
||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
try {
|
||||
if (version < 17) {
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
if (version == 13) {
|
||||
this.mustSave = classChunk.getField("mustSave");
|
||||
this.isTrueForNotSave = false;
|
||||
} else {
|
||||
this.mustSave = classChunk.getField("mustNotSave");
|
||||
}
|
||||
} else {
|
||||
RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.Chunk");
|
||||
this.mustSave = classChunk.getField("mustNotSave");
|
||||
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
Settings.Chunk_Processor.AUTO_TRIM = false;
|
||||
}
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
world.setAutoSave(false);
|
||||
}
|
||||
if (version > 13) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskRepeat(() -> {
|
||||
try {
|
||||
HashSet<Chunk> toUnload = new HashSet<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
continue;
|
||||
}
|
||||
Object craftWorld = methodGetHandleWorld.of(world).call();
|
||||
if (version == 13) {
|
||||
Object chunkMap = craftWorld.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(craftWorld);
|
||||
Method methodIsChunkInUse =
|
||||
chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
for (Chunk chunk : chunks) {
|
||||
if ((boolean) methodIsChunkInUse.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||
continue;
|
||||
}
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
if (!shouldSave(worldName, x, z)) {
|
||||
unloadChunk(worldName, chunk, false);
|
||||
continue;
|
||||
}
|
||||
toUnload.add(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toUnload.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (Chunk chunk : toUnload) {
|
||||
if (System.currentTimeMillis() - start > 5) {
|
||||
return;
|
||||
}
|
||||
chunk.unload(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, TaskTime.ticks(1L));
|
||||
}
|
||||
|
||||
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
|
||||
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
|
||||
return false;
|
||||
}
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
RefField.RefExecutor field = this.mustSave.of(c);
|
||||
if ((Boolean) field.get() != isTrueForNotSave) {
|
||||
field.set(isTrueForNotSave);
|
||||
if (chunk.isLoaded()) {
|
||||
ignoreUnload = true;
|
||||
chunk.unload(false);
|
||||
ignoreUnload = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldSave(String world, int chunkX, int chunkZ) {
|
||||
int x = chunkX << 4;
|
||||
int z = chunkZ << 4;
|
||||
int x2 = x + 15;
|
||||
int z2 = z + 15;
|
||||
Location loc = Location.at(world, x, 1, z);
|
||||
PlotArea plotArea = plotAreaManager.getPlotArea(loc);
|
||||
if (plotArea != null) {
|
||||
Plot plot = plotArea.getPlot(loc);
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
loc = Location.at(world, x2, 1, z2);
|
||||
plotArea = plotAreaManager.getPlotArea(loc);
|
||||
if (plotArea != null) {
|
||||
Plot plot = plotArea.getPlot(loc);
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
loc = Location.at(world, x2, 1, z);
|
||||
plotArea = plotAreaManager.getPlotArea(loc);
|
||||
if (plotArea != null) {
|
||||
Plot plot = plotArea.getPlot(loc);
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
loc = Location.at(world, x, 1, z2);
|
||||
plotArea = plotAreaManager.getPlotArea(loc);
|
||||
if (plotArea != null) {
|
||||
Plot plot = plotArea.getPlot(loc);
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
loc = Location.at(world, x + 7, 1, z + 7);
|
||||
plotArea = plotAreaManager.getPlotArea(loc);
|
||||
if (plotArea == null) {
|
||||
return false;
|
||||
}
|
||||
Plot plot = plotArea.getPlot(loc);
|
||||
return plot != null && plot.hasOwner();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
if (ignoreUnload) {
|
||||
return;
|
||||
}
|
||||
Chunk chunk = event.getChunk();
|
||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||
String world = chunk.getWorld().getName();
|
||||
if ((!Settings.Enabled_Components.WORLDS || !SinglePlotArea.isSinglePlotWorld(world)) && this.plotAreaManager.hasPlotArea(world)) {
|
||||
if (unloadChunk(world, chunk, true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (processChunk(event.getChunk(), true)) {
|
||||
chunk.setForceLoaded(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
processChunk(event.getChunk(), false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
Item entity = event.getEntity();
|
||||
PaperLib.getChunkAtAsync(event.getLocation()).thenAccept(chunk -> {
|
||||
if (chunk == this.lastChunk) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
this.lastChunk = chunk;
|
||||
} else {
|
||||
this.lastChunk = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
if (Settings.Chunk_Processor.DISABLE_PHYSICS) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntitySpawn(CreatureSpawnEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
PaperLib.getChunkAtAsync(event.getLocation()).thenAccept(chunk -> {
|
||||
if (chunk == this.lastChunk) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
this.lastChunk = chunk;
|
||||
} else {
|
||||
this.lastChunk = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void cleanChunk(final Chunk chunk) {
|
||||
final int currentIndex = TaskManager.index.incrementAndGet();
|
||||
PlotSquaredTask task = TaskManager.runTaskRepeat(() -> {
|
||||
if (!chunk.isLoaded()) {
|
||||
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
BlockState[] tiles = chunk.getTileEntities();
|
||||
if (tiles.length == 0) {
|
||||
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
int i = 0;
|
||||
while (System.currentTimeMillis() - start < 250) {
|
||||
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
|
||||
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
i++;
|
||||
}
|
||||
}, TaskTime.ticks(5L));
|
||||
TaskManager.addTask(task, currentIndex);
|
||||
}
|
||||
|
||||
public boolean processChunk(Chunk chunk, boolean unload) {
|
||||
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
Entity[] entities = chunk.getEntities();
|
||||
BlockState[] tiles = chunk.getTileEntities();
|
||||
if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) {
|
||||
int toRemove = entities.length - Settings.Chunk_Processor.MAX_ENTITIES;
|
||||
int index = 0;
|
||||
while (toRemove > 0 && index < entities.length) {
|
||||
final Entity entity = entities[index++];
|
||||
if (!(entity instanceof Player)) {
|
||||
entity.remove();
|
||||
toRemove--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
||||
if (unload) {
|
||||
cleanChunk(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (tiles.length - Settings.Chunk_Processor.MAX_TILES); i++) {
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,439 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.listener.PlayerBlockEventType;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotHandler;
|
||||
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityEventListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
private float lastRadius;
|
||||
|
||||
@Inject
|
||||
public EntityEventListener(
|
||||
final @NonNull PlotAreaManager plotAreaManager,
|
||||
final @NonNull EventDispatcher eventDispatcher
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
EntityDamageByEntityEvent eventChange =
|
||||
new EntityDamageByEntityEvent(
|
||||
event.getCombuster(),
|
||||
event.getEntity(),
|
||||
EntityDamageEvent.DamageCause.FIRE_TICK,
|
||||
event.getDuration()
|
||||
);
|
||||
onEntityDamageByEntityEvent(eventChange);
|
||||
if (eventChange.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
Entity victim = event.getEntity();
|
||||
/*
|
||||
if (victim.getType().equals(EntityType.ITEM_FRAME)) {
|
||||
Plot plot = BukkitUtil.getLocation(victim).getPlot();
|
||||
if (plot != null && !plot.isAdded(damager.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim, event.getCause())) {
|
||||
if (event.isCancelled()) {
|
||||
if (victim instanceof Ageable ageable) {
|
||||
if (ageable.getAge() == -24000) {
|
||||
ageable.setAge(0);
|
||||
ageable.setAdult();
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
|
||||
switch (reason.toString()) {
|
||||
case "DISPENSE_EGG":
|
||||
case "EGG":
|
||||
case "OCELOT_BABY":
|
||||
case "SPAWNER_EGG":
|
||||
if (!area.isSpawnEggs()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "REINFORCEMENTS":
|
||||
case "NATURAL":
|
||||
case "MOUNT":
|
||||
case "PATROL":
|
||||
case "RAID":
|
||||
case "SHEARED":
|
||||
case "SILVERFISH_BLOCK":
|
||||
case "ENDER_PEARL":
|
||||
case "TRAP":
|
||||
case "VILLAGE_DEFENSE":
|
||||
case "VILLAGE_INVASION":
|
||||
case "BEEHIVE":
|
||||
case "CHUNK_GEN":
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BREEDING":
|
||||
if (!area.isSpawnBreeding()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BUILD_IRONGOLEM":
|
||||
case "BUILD_SNOWMAN":
|
||||
case "BUILD_WITHER":
|
||||
case "CUSTOM":
|
||||
if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "SPAWNER":
|
||||
if (!area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot.getBasePlot(false))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityFall(EntityChangeBlockEvent event) {
|
||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
String worldName = world.getName();
|
||||
if (!this.plotAreaManager.hasPlotArea(worldName)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
if (plot != null) {
|
||||
if (block.getType().hasGravity()) {
|
||||
BlockEventListener.sendBlockChange(block.getLocation(), block.getBlockData());
|
||||
}
|
||||
plot.debug("Falling block event was cancelled because disable-physics = true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.getTo().hasGravity()) {
|
||||
Entity entity = event.getEntity();
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (origin != null && !origin.equals(plot)) {
|
||||
event.setCancelled(true);
|
||||
entity.remove();
|
||||
}
|
||||
} else if (event.getTo() == Material.AIR) {
|
||||
event.getEntity().setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, InvincibleFlag.class, true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(InvincibleFlag.class)) {
|
||||
plot.debug(event.getEntity().getName() + " could not take damage because invincible = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(EntityExplodeEvent event) {
|
||||
Location location = BukkitUtil.adapt(event.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
boolean plotArea = location.isPlotArea();
|
||||
if (!plotArea) {
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null) {
|
||||
if (plot.getFlag(ExplosionFlag.class)) {
|
||||
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
|
||||
Plot origin;
|
||||
if (meta.isEmpty()) {
|
||||
origin = plot;
|
||||
} else {
|
||||
origin = (Plot) meta.get(0).value();
|
||||
}
|
||||
if (this.lastRadius != 0) {
|
||||
List<Entity> nearby = event.getEntity().getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
|
||||
for (Entity near : nearby) {
|
||||
if (near instanceof TNTPrimed || near.getType().equals(EntityType.MINECART_TNT)) {
|
||||
if (!near.hasMetadata("plot")) {
|
||||
near.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastRadius = 0;
|
||||
}
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Block block = iterator.next();
|
||||
location = BukkitUtil.adapt(block.getLocation());
|
||||
if (!area.contains(location.getX(), location.getZ()) || !origin.equals(area.getOwnedPlot(location))) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
plot.debug("Explosion was cancelled because explosion = false");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
//Spawn Explosion Particles when enabled in settings
|
||||
if (Settings.General.ALWAYS_SHOW_EXPLOSIONS) {
|
||||
event.getLocation().getWorld().spawnParticle(Particle.EXPLOSION_HUGE, event.getLocation(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||
Entity e = event.getEntity();
|
||||
Material type = event.getBlock().getType();
|
||||
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
if (e instanceof FallingBlock) {
|
||||
// allow falling blocks converting to blocks and vice versa
|
||||
return;
|
||||
} else if (e instanceof Boat) {
|
||||
// allow boats destroying lily pads
|
||||
if (type == Material.LILY_PAD) {
|
||||
return;
|
||||
}
|
||||
} else if (e instanceof Player player) {
|
||||
BukkitPlayer pp = BukkitUtil.adapt(player);
|
||||
if (type.toString().equals("POWDER_SNOW")) {
|
||||
// Burning player evaporating powder snow. Use same checks as
|
||||
// trampling farmland
|
||||
BlockType blockType = BukkitAdapter.asBlockType(type);
|
||||
if (!this.eventDispatcher.checkPlayerBlockEvent(pp,
|
||||
PlayerBlockEventType.TRIGGER_PHYSICAL, location, blockType, true
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// already handled by other flags (mainly the 'use' flag):
|
||||
// - player tilting big dripleaf by standing on it
|
||||
// - player picking glow berries from cave vine
|
||||
// - player trampling farmland
|
||||
// - player standing on or clicking redstone ore
|
||||
return;
|
||||
}
|
||||
} else if (e instanceof Projectile entity) {
|
||||
// Exact same as the ProjectileHitEvent listener, except that we let
|
||||
// the entity-change-block determine what to do with shooters that
|
||||
// aren't players and aren't blocks
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
||||
return;
|
||||
}
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!(shooter instanceof Entity) && shooter != null) {
|
||||
if (plot == null) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Location sLoc =
|
||||
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Plot sPlot = area.getOwnedPlotAbs(sLoc);
|
||||
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// fall back to entity-change-block flag
|
||||
}
|
||||
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null && !plot.getFlag(EntityChangeBlockFlag.class)) {
|
||||
plot.debug(e.getType() + " could not change block because entity-change-block = false");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPrime(ExplosionPrimeEvent event) {
|
||||
this.lastRadius = event.getRadius() + 1;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVehicleCreate(VehicleCreateEvent event) {
|
||||
Vehicle entity = event.getVehicle();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
entity.remove();
|
||||
return;
|
||||
}
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,231 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
|
||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.event.vehicle.VehicleUpdateEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntitySpawnListener implements Listener {
|
||||
|
||||
private static final String KEY = "P2";
|
||||
private static boolean ignoreTP = false;
|
||||
private static boolean hasPlotArea = false;
|
||||
private static String areaName = null;
|
||||
|
||||
public static void testNether(final Entity entity) {
|
||||
@NonNull World world = entity.getWorld();
|
||||
if (world.getEnvironment() != World.Environment.NETHER && world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
test(entity);
|
||||
}
|
||||
|
||||
public static void testCreate(final Entity entity) {
|
||||
@NonNull World world = entity.getWorld();
|
||||
if (!world.getName().equals(areaName)) {
|
||||
areaName = world.getName();
|
||||
hasPlotArea = PlotSquared.get().getPlotAreaManager().hasPlotArea(areaName);
|
||||
}
|
||||
if (!hasPlotArea) {
|
||||
return;
|
||||
}
|
||||
test(entity);
|
||||
}
|
||||
|
||||
public static void test(Entity entity) {
|
||||
@NonNull World world = entity.getWorld();
|
||||
List<MetadataValue> meta = entity.getMetadata(KEY);
|
||||
if (meta.isEmpty()) {
|
||||
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
|
||||
entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
|
||||
}
|
||||
} else {
|
||||
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
|
||||
World originWorld = origin.getWorld();
|
||||
if (!originWorld.equals(world)) {
|
||||
if (!ignoreTP) {
|
||||
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
|
||||
if (entity.getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ignoreTP = true;
|
||||
PaperLib.teleportAsync(entity, origin);
|
||||
} finally {
|
||||
ignoreTP = false;
|
||||
}
|
||||
if (entity.getLocation().getWorld().equals(world)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (entity.getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlotAbs();
|
||||
EntityType type = entity.getType();
|
||||
if (plot == null) {
|
||||
if (type == EntityType.DROPPED_ITEM) {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!area.isMobSpawning()) {
|
||||
if (type == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
if (type.isAlive()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!area.isMiscSpawnUnowned() && !type.isAlive()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (type == EntityType.ENDER_CRYSTAL) {
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type == EntityType.SHULKER) {
|
||||
if (!entity.hasMetadata("shulkerPlot")) {
|
||||
entity.setMetadata("shulkerPlot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
@NonNull Chunk chunk = event.getChunk();
|
||||
for (final Entity entity : chunk.getEntities()) {
|
||||
testCreate(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicle(VehicleUpdateEvent event) {
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicle(VehicleCreateEvent event) {
|
||||
testCreate(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVehicle(VehicleBlockCollisionEvent event) {
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(EntityTeleportEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Entity fromLocation = event.getEntity();
|
||||
Block toLocation = event.getTo().getBlock();
|
||||
final Location fromLocLocation = BukkitUtil.adapt(fromLocation.getLocation());
|
||||
final PlotArea fromArea = fromLocLocation.getPlotArea();
|
||||
Location toLocLocation = BukkitUtil.adapt(toLocation.getLocation());
|
||||
PlotArea toArea = toLocLocation.getPlotArea();
|
||||
|
||||
if (toArea == null) {
|
||||
if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot toPlot = toArea.getOwnedPlot(toLocLocation);
|
||||
if (fromLocation.getType() == EntityType.SHULKER && fromArea != null) {
|
||||
final Plot fromPlot = fromArea.getOwnedPlot(fromLocLocation);
|
||||
|
||||
if (fromPlot != null || toPlot != null) {
|
||||
if ((fromPlot == null || !fromPlot.equals(toPlot)) && (toPlot == null || !toPlot.equals(fromPlot))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity instanceof Vehicle || entity instanceof ArmorStand) {
|
||||
testNether(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void vehicleMove(VehicleMoveEvent event) {
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void spawn(CreatureSpawnEvent event) {
|
||||
if (event.getEntityType() == EntityType.ARMOR_STAND) {
|
||||
testCreate(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.implementations.ForcefieldFlag;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ForceFieldListener {
|
||||
|
||||
private static Set<PlotPlayer<?>> getNearbyPlayers(Player player, Plot plot) {
|
||||
Set<PlotPlayer<?>> players = new HashSet<>();
|
||||
for (Player nearPlayer : player.getNearbyEntities(5d, 5d, 5d).stream()
|
||||
.filter(entity -> entity instanceof Player)
|
||||
.map(entity -> (Player) entity)
|
||||
.toList()
|
||||
) {
|
||||
PlotPlayer<?> plotPlayer;
|
||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||
.equals(plotPlayer.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||
players.add(plotPlayer);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
private static PlotPlayer<?> hasNearbyPermitted(Player player, Plot plot) {
|
||||
for (Player nearPlayer : player.getNearbyEntities(5d, 5d, 5d).stream()
|
||||
.filter(entity -> entity instanceof Player)
|
||||
.map(entity -> (Player) entity)
|
||||
.toList()
|
||||
) {
|
||||
PlotPlayer<?> plotPlayer;
|
||||
if ((plotPlayer = BukkitUtil.adapt(nearPlayer)) == null || !plot
|
||||
.equals(plotPlayer.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
if (plot.isAdded(plotPlayer.getUUID())) {
|
||||
return plotPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Vector calculateVelocity(PlotPlayer<?> player, PlotPlayer<?> e) {
|
||||
Location playerLocation = player.getLocationFull();
|
||||
Location oPlayerLocation = e.getLocation();
|
||||
double playerX = playerLocation.getX();
|
||||
double playerY = playerLocation.getY();
|
||||
double playerZ = playerLocation.getZ();
|
||||
double oPlayerX = oPlayerLocation.getX();
|
||||
double oPlayerY = oPlayerLocation.getY();
|
||||
double oPlayerZ = oPlayerLocation.getZ();
|
||||
double x = 0d;
|
||||
if (playerX < oPlayerX) {
|
||||
x = 1.0d;
|
||||
} else if (playerX > oPlayerX) {
|
||||
x = -1.0d;
|
||||
}
|
||||
double y = 0d;
|
||||
if (playerY < oPlayerY) {
|
||||
y = 0.5d;
|
||||
} else if (playerY > oPlayerY) {
|
||||
y = -0.5d;
|
||||
}
|
||||
double z = 0d;
|
||||
if (playerZ < oPlayerZ) {
|
||||
z = 1.0d;
|
||||
} else if (playerZ > oPlayerZ) {
|
||||
z = -1.0d;
|
||||
}
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public static void handleForcefield(Player player, PlotPlayer<?> plotPlayer, Plot plot) {
|
||||
if (plot.getFlag(ForcefieldFlag.class)) {
|
||||
UUID uuid = plotPlayer.getUUID();
|
||||
if (plot.isAdded(uuid)) {
|
||||
Set<PlotPlayer<?>> players = getNearbyPlayers(player, plot);
|
||||
for (PlotPlayer<?> oPlayer : players) {
|
||||
if (!oPlayer.hasPermission(Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
((BukkitPlayer) oPlayer).player
|
||||
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PlotPlayer<?> oPlayer = hasNearbyPermitted(player, plot);
|
||||
if (oPlayer == null) {
|
||||
return;
|
||||
}
|
||||
if (!plotPlayer.hasPermission(Permission.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,456 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
|
||||
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
|
||||
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.command.Command;
|
||||
import com.plotsquared.core.command.MainCommand;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.FlagContainer;
|
||||
import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
|
||||
import com.plotsquared.core.plot.flag.types.BooleanFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Events specific to Paper. Some toit nups here
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PaperListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
private Chunk lastChunk;
|
||||
|
||||
@Inject
|
||||
public PaperListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPathfind(EntityPathfindEvent event) {
|
||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||
return;
|
||||
}
|
||||
Location toLoc = BukkitUtil.adapt(event.getLoc());
|
||||
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea tarea = toLoc.getPlotArea();
|
||||
if (tarea == null) {
|
||||
return;
|
||||
}
|
||||
PlotArea farea = fromLoc.getPlotArea();
|
||||
if (farea == null) {
|
||||
return;
|
||||
}
|
||||
if (tarea != farea) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Plot tplot = toLoc.getPlot();
|
||||
Plot fplot = fromLoc.getPlot();
|
||||
if (tplot == null ^ fplot == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
|
||||
return;
|
||||
}
|
||||
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPathfind(SlimePathfindEvent event) {
|
||||
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
||||
return;
|
||||
}
|
||||
Slime slime = event.getEntity();
|
||||
|
||||
Block b = slime.getTargetBlock(4);
|
||||
if (b == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location toLoc = BukkitUtil.adapt(b.getLocation());
|
||||
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
||||
PlotArea tarea = toLoc.getPlotArea();
|
||||
if (tarea == null) {
|
||||
return;
|
||||
}
|
||||
PlotArea farea = fromLoc.getPlotArea();
|
||||
if (farea == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tarea != farea) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Plot tplot = toLoc.getPlot();
|
||||
Plot fplot = fromLoc.getPlot();
|
||||
if (tplot == null ^ fplot == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
|
||||
return;
|
||||
}
|
||||
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
|
||||
if (!Settings.Paper_Components.CREATURE_SPAWN) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(event.getSpawnLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
//If entities are spawning... the chunk should be loaded?
|
||||
Entity[] entities = event.getSpawnLocation().getChunk().getEntities();
|
||||
if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
CreatureSpawnEvent.SpawnReason reason = event.getReason();
|
||||
switch (reason.toString()) {
|
||||
case "DISPENSE_EGG":
|
||||
case "EGG":
|
||||
case "OCELOT_BABY":
|
||||
case "SPAWNER_EGG":
|
||||
if (!area.isSpawnEggs()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "REINFORCEMENTS":
|
||||
case "NATURAL":
|
||||
case "MOUNT":
|
||||
case "PATROL":
|
||||
case "RAID":
|
||||
case "SHEARED":
|
||||
case "SILVERFISH_BLOCK":
|
||||
case "ENDER_PEARL":
|
||||
case "TRAP":
|
||||
case "VILLAGE_DEFENSE":
|
||||
case "VILLAGE_INVASION":
|
||||
case "BEEHIVE":
|
||||
case "CHUNK_GEN":
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BREEDING":
|
||||
if (!area.isSpawnBreeding()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BUILD_IRONGOLEM":
|
||||
case "BUILD_SNOWMAN":
|
||||
case "BUILD_WITHER":
|
||||
case "CUSTOM":
|
||||
if (!area.isSpawnCustom() && event.getType() != EntityType.ARMOR_STAND) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "SPAWNER":
|
||||
if (!area.isMobSpawnerSpawning()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Plot plot = location.getOwnedPlotAbs();
|
||||
if (plot == null) {
|
||||
EntityType type = event.getType();
|
||||
// PreCreatureSpawnEvent **should** not be called for DROPPED_ITEM, just for the sake of consistency
|
||||
if (type == EntityType.DROPPED_ITEM) {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!area.isMobSpawning()) {
|
||||
if (type == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
if (type.isAlive()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!area.isMiscSpawnUnowned() && !type.isAlive()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerNaturallySpawnCreaturesEvent(PlayerNaturallySpawnCreaturesEvent event) {
|
||||
if (Settings.Paper_Components.CANCEL_CHUNK_SPAWN) {
|
||||
Location location = BukkitUtil.adapt(event.getPlayer().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
||||
if (Settings.Paper_Components.SPAWNER_SPAWN) {
|
||||
Location location = BukkitUtil.adapt(event.getSpawnerLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
event.setShouldAbortSpawn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getBlock().getState(false) instanceof TileState)) {
|
||||
return;
|
||||
}
|
||||
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
final PlotArea plotArea = location.getPlotArea();
|
||||
if (plotArea == null) {
|
||||
return;
|
||||
}
|
||||
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("errors.tile_entity_cap_reached"),
|
||||
Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES))
|
||||
);
|
||||
event.setCancelled(true);
|
||||
event.setBuild(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsure if this will be any performance improvement over the spigot version,
|
||||
* but here it is anyway :)
|
||||
*
|
||||
* @param event Paper's PlayerLaunchProjectileEvent
|
||||
*/
|
||||
@EventHandler
|
||||
public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
||||
if (!Settings.Paper_Components.PLAYER_PROJECTILE) {
|
||||
return;
|
||||
}
|
||||
Projectile entity = event.getProjectile();
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
|
||||
if (plot == null) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !pp.hasPermission(
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!plot.hasOwner()) {
|
||||
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!plot.isAdded(pp.getUUID())) {
|
||||
if (!plot.getFlag(ProjectilesFlag.class)) {
|
||||
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
||||
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
||||
return;
|
||||
}
|
||||
String buffer = event.getBuffer();
|
||||
if (!(event.getSender() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) {
|
||||
return;
|
||||
}
|
||||
if (buffer.startsWith("/")) {
|
||||
buffer = buffer.substring(1);
|
||||
}
|
||||
final String[] unprocessedArgs = buffer.split(Pattern.quote(" "));
|
||||
if (unprocessedArgs.length == 1) {
|
||||
return; // We don't do anything in this case
|
||||
} else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
|
||||
.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
|
||||
return;
|
||||
}
|
||||
final String[] args = new String[unprocessedArgs.length - 1];
|
||||
System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
|
||||
try {
|
||||
final PlotPlayer<?> player = BukkitUtil.adapt((Player) event.getSender());
|
||||
final Collection<Command> objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
|
||||
if (objects == null) {
|
||||
return;
|
||||
}
|
||||
final List<String> result = new ArrayList<>();
|
||||
for (final com.plotsquared.core.command.Command o : objects) {
|
||||
result.add(o.toString());
|
||||
}
|
||||
event.setCompletions(result);
|
||||
event.setHandled(true);
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBeaconEffect(final BeaconEffectEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location beaconLocation = BukkitUtil.adapt(block.getLocation());
|
||||
Plot beaconPlot = beaconLocation.getPlot();
|
||||
|
||||
PlotArea area = beaconLocation.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location playerLocation = BukkitUtil.adapt(player.getLocation());
|
||||
|
||||
PlotPlayer<Player> plotPlayer = BukkitUtil.adapt(player);
|
||||
Plot playerStandingPlot = playerLocation.getPlot();
|
||||
if (playerStandingPlot == null) {
|
||||
FlagContainer container = area.getRoadFlagContainer();
|
||||
if (!getBooleanFlagValue(container, BeaconEffectsFlag.class, true) ||
|
||||
(beaconPlot != null && Settings.Enabled_Components.DISABLE_BEACON_EFFECT_OVERFLOW)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FlagContainer container = playerStandingPlot.getFlagContainer();
|
||||
boolean plotBeaconEffects = getBooleanFlagValue(container, BeaconEffectsFlag.class, true);
|
||||
if (playerStandingPlot.equals(beaconPlot)) {
|
||||
if (!plotBeaconEffects) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plotBeaconEffects || Settings.Enabled_Components.DISABLE_BEACON_EFFECT_OVERFLOW) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getBooleanFlagValue(@NonNull FlagContainer container,
|
||||
@NonNull Class<? extends BooleanFlag<?>> flagClass,
|
||||
boolean defaultValue) {
|
||||
BooleanFlag<?> flag = container.getFlag(flagClass);
|
||||
return flag == null ? defaultValue : flag.getValue();
|
||||
}
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Beacon;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.block.Comparator;
|
||||
import org.bukkit.block.Conduit;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.DaylightDetector;
|
||||
import org.bukkit.block.EnchantingTable;
|
||||
import org.bukkit.block.EndGateway;
|
||||
import org.bukkit.block.EnderChest;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.block.Structure;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* @deprecated P2 effectively no longer supports 1.13
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "6.10.4")
|
||||
public class PaperListener113 extends PaperListener {
|
||||
|
||||
@Inject
|
||||
public PaperListener113(@NonNull PlotAreaManager plotAreaManager) {
|
||||
super(plotAreaManager);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
||||
return;
|
||||
}
|
||||
BlockState state = event.getBlock().getState(false);
|
||||
if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock
|
||||
|| state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner
|
||||
|| state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway
|
||||
|| state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
|
||||
return;
|
||||
}
|
||||
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
||||
final PlotArea plotArea = location.getPlotArea();
|
||||
if (plotArea == null) {
|
||||
return;
|
||||
}
|
||||
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
||||
plotPlayer.sendMessage(
|
||||
TranslatableCaption.of("errors.tile_entity_cap_reached"),
|
||||
Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES))
|
||||
);
|
||||
event.setCancelled(true);
|
||||
event.setBuild(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotHandler;
|
||||
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.PlotFlagUtil;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ProjectileEventListener implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject
|
||||
public ProjectileEventListener(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
|
||||
// Cancelling projectile hit events still results in area effect clouds.
|
||||
// We need to cancel the splash events to get rid of those.
|
||||
onProjectileHit(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
ThrownPotion damager = event.getPotion();
|
||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (LivingEntity victim : event.getAffectedEntities()) {
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim)) {
|
||||
event.setIntensity(victim, 0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0 && count == event.getAffectedEntities().size()) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
// Cancelling projectile hit events still results in potions
|
||||
// splashing in the world. We need to cancel the splash events to
|
||||
// avoid that.
|
||||
onProjectileHit(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
|
||||
if (plot == null) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !pp.hasPermission(
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
|
||||
)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!plot.hasOwner()) {
|
||||
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (!plot.isAdded(pp.getUUID())) {
|
||||
if (!plot.getFlag(ProjectilesFlag.class)) {
|
||||
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
||||
pp.sendMessage(
|
||||
TranslatableCaption.of("permission.no_permission_event"),
|
||||
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
|
||||
);
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileHit(ProjectileHitEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
if (!((Player) shooter).isOnline()) {
|
||||
if (plot != null) {
|
||||
if (plot.isAdded(((Player) shooter).getUniqueId()) || plot.getFlag(ProjectilesFlag.class)) {
|
||||
return;
|
||||
}
|
||||
} else if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !pp.hasPermission(
|
||||
Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED
|
||||
)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag(
|
||||
ProjectilesFlag.class)) {
|
||||
return;
|
||||
}
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!(shooter instanceof Entity) && shooter != null) {
|
||||
if (plot == null) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Location sLoc =
|
||||
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Plot sPlot = area.getOwnedPlotAbs(sLoc);
|
||||
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.placeholder.MVdWPlaceholders;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ServerListener implements Listener {
|
||||
|
||||
private final BukkitPlatform plugin;
|
||||
|
||||
@Inject
|
||||
public ServerListener(final @NonNull BukkitPlatform plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent event) {
|
||||
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null && Settings.Enabled_Components.USE_MVDWAPI) {
|
||||
new MVdWPlaceholders(this.plugin, this.plugin.placeholderRegistry());
|
||||
ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("placeholder.hooked"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import com.plotsquared.core.util.ReflectionUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public class SingleWorldListener implements Listener {
|
||||
|
||||
private final Method methodGetHandleChunk;
|
||||
private Field shouldSave = null;
|
||||
|
||||
public SingleWorldListener() throws Exception {
|
||||
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
|
||||
try {
|
||||
if (PlotSquared.platform().serverVersion()[1] < 17) {
|
||||
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
if (PlotSquared.platform().serverVersion()[1] == 13) {
|
||||
this.shouldSave = classChunk.getField("mustSave").getRealField();
|
||||
} else {
|
||||
this.shouldSave = classChunk.getField("s").getRealField();
|
||||
}
|
||||
} else if (PlotSquared.platform().serverVersion()[1] == 17) {
|
||||
ReflectionUtils.RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.Chunk");
|
||||
this.shouldSave = classChunk.getField("r").getRealField();
|
||||
} else if (PlotSquared.platform().serverVersion()[1] == 18) {
|
||||
ReflectionUtils.RefClass classChunk = getRefClass("net.minecraft.world.level.chunk.IChunkAccess");
|
||||
this.shouldSave = classChunk.getField("b").getRealField();
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void markChunkAsClean(Chunk chunk) {
|
||||
try {
|
||||
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
||||
if (shouldSave != null) {
|
||||
this.shouldSave.set(nmsChunk, false);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(ChunkEvent event) {
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
PlotAreaManager man = PlotSquared.get().getPlotAreaManager();
|
||||
if (!(man instanceof SinglePlotAreaManager)) {
|
||||
return;
|
||||
}
|
||||
if (!SinglePlotArea.isSinglePlotWorld(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
markChunkAsClean(event.getChunk());
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onPopulate(ChunkPopulateEvent event) {
|
||||
// handle(event);
|
||||
// }
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
handle(event);
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.FlagContainer;
|
||||
import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Fallback listener for paper events on spigot
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEffect(@NonNull EntityPotionEffectEvent event) {
|
||||
if (event.getCause() != EntityPotionEffectEvent.Cause.BEACON) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FlagContainer container = plot.getFlagContainer();
|
||||
BeaconEffectsFlag effectsEnabled = container.getFlag(BeaconEffectsFlag.class);
|
||||
if (effectsEnabled != null && !effectsEnabled.getValue()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class WorldEvents implements Listener {
|
||||
|
||||
private final PlotAreaManager plotAreaManager;
|
||||
|
||||
@Inject
|
||||
public WorldEvents(final @NonNull PlotAreaManager plotAreaManager) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
if (this.plotAreaManager instanceof final SinglePlotAreaManager single) {
|
||||
if (single.isWorld(name)) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof GeneratorWrapper) {
|
||||
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||
} else {
|
||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,325 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class ChunkListener implements Listener {
|
||||
|
||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
private final RefField mustSave = classChunk.getField("mustSave");
|
||||
private Chunk lastChunk = null;
|
||||
private RefMethod methodGetHandleChunk;
|
||||
|
||||
|
||||
public ChunkListener() {
|
||||
RefMethod method;
|
||||
try {
|
||||
method = classCraftChunk.getMethod("getHandle");
|
||||
} catch (final Exception e) {
|
||||
method = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
methodGetHandleChunk = method;
|
||||
|
||||
if (!Settings.CHUNK_PROCESSOR_GC) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final int distance = Bukkit.getViewDistance() + 2;
|
||||
final HashMap<String, HashMap<ChunkLoc, Integer>> players = new HashMap<>();
|
||||
for (final Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
final PlotPlayer pp = entry.getValue();
|
||||
final Location loc = pp.getLocation();
|
||||
final String world = loc.getWorld();
|
||||
if (!PS.get().hasPlotArea(world)) {
|
||||
continue;
|
||||
}
|
||||
HashMap<ChunkLoc, Integer> map = players.get(world);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
players.put(world, map);
|
||||
}
|
||||
final ChunkLoc origin = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||
Integer val = map.get(origin);
|
||||
int check;
|
||||
if (val != null) {
|
||||
if (val == distance) {
|
||||
continue;
|
||||
}
|
||||
check = distance - val;
|
||||
} else {
|
||||
check = distance;
|
||||
map.put(origin, distance);
|
||||
}
|
||||
for (int x = -distance; x <= distance; x++) {
|
||||
if (x >= check || -x >= check) {
|
||||
continue;
|
||||
}
|
||||
for (int z = -distance; z <= distance; z++) {
|
||||
if (z >= check || -z >= check) {
|
||||
continue;
|
||||
}
|
||||
final int weight = distance - Math.max(Math.abs(x), Math.abs(z));
|
||||
final ChunkLoc chunk = new ChunkLoc(x + origin.x, z + origin.z);
|
||||
val = map.get(chunk);
|
||||
if (val == null || val < weight) {
|
||||
map.put(chunk, weight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
int time = 300;
|
||||
for (final World world : Bukkit.getWorlds()) {
|
||||
final String name = world.getName();
|
||||
if (!PS.get().hasPlotArea(name)) {
|
||||
continue;
|
||||
}
|
||||
final boolean autosave = world.isAutoSave();
|
||||
if (autosave) {
|
||||
world.setAutoSave(false);
|
||||
}
|
||||
final HashMap<ChunkLoc, Integer> map = players.get(name);
|
||||
if (map == null || map.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
ArrayDeque<Chunk> toUnload = new ArrayDeque<>();
|
||||
for (final Chunk chunk : chunks) {
|
||||
final int x = chunk.getX();
|
||||
final int z = chunk.getZ();
|
||||
if (!map.containsKey(new ChunkLoc(x, z))) {
|
||||
toUnload.add(chunk);
|
||||
}
|
||||
}
|
||||
if (!toUnload.isEmpty()) {
|
||||
long start = System.currentTimeMillis();
|
||||
Chunk chunk;
|
||||
while ((chunk = toUnload.poll()) != null && System.currentTimeMillis() - start < 5) {
|
||||
if (!Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE || !unloadChunk(name, chunk)) {
|
||||
if (chunk.isLoaded()) {
|
||||
chunk.unload(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!toUnload.isEmpty()) {
|
||||
time = 1;
|
||||
}
|
||||
}
|
||||
if (!Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE && autosave) {
|
||||
world.setAutoSave(true);
|
||||
}
|
||||
}
|
||||
TaskManager.runTaskLater(this, time);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean unloadChunk(final String world, final Chunk chunk) {
|
||||
final int X = chunk.getX();
|
||||
final int Z = chunk.getZ();
|
||||
final int x = X << 4;
|
||||
final int z = Z << 4;
|
||||
final int x2 = x + 15;
|
||||
final int z2 = z + 15;
|
||||
Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
plot = new Location(world, x2, 1, z2).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
plot = new Location(world, x2, 1, z).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
plot = new Location(world, x, 1, z2).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
plot = new Location(world, x + 7, 1, z + 7).getOwnedPlotAbs();
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||
mustSave.of(c).set(false);
|
||||
if (chunk.isLoaded()) {
|
||||
chunk.unload(false, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(final ChunkUnloadEvent event) {
|
||||
if (Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE) {
|
||||
final Chunk chunk = event.getChunk();
|
||||
final String world = chunk.getWorld().getName();
|
||||
if (PS.get().hasPlotArea(world)) {
|
||||
if (unloadChunk(world, chunk)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (processChunk(event.getChunk(), true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(final ChunkLoadEvent event) {
|
||||
processChunk(event.getChunk(), false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onItemSpawn(final ItemSpawnEvent event) {
|
||||
final Item entity = event.getEntity();
|
||||
final Chunk chunk = entity.getLocation().getChunk();
|
||||
if (chunk == lastChunk) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
final Entity[] entities = chunk.getEntities();
|
||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
lastChunk = chunk;
|
||||
} else {
|
||||
lastChunk = null;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPhysics(final BlockPhysicsEvent event) {
|
||||
if (Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntitySpawn(final CreatureSpawnEvent event) {
|
||||
final LivingEntity entity = event.getEntity();
|
||||
final Chunk chunk = entity.getLocation().getChunk();
|
||||
if (chunk == lastChunk) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
final Entity[] entities = chunk.getEntities();
|
||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||
event.getEntity().remove();
|
||||
event.setCancelled(true);
|
||||
lastChunk = chunk;
|
||||
} else {
|
||||
lastChunk = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanChunk(final Chunk chunk) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!chunk.isLoaded()) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
final BlockState[] tiles = chunk.getTileEntities();
|
||||
if (tiles.length == 0) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
final long start = System.currentTimeMillis();
|
||||
int i = 0;
|
||||
while (System.currentTimeMillis() - start < 250) {
|
||||
if (i >= tiles.length) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PS.debug("[PlotSquared] &aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}, 5);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
}
|
||||
|
||||
public boolean processChunk(final Chunk chunk, final boolean unload) {
|
||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||
return false;
|
||||
}
|
||||
final Entity[] entities = chunk.getEntities();
|
||||
final BlockState[] tiles = chunk.getTileEntities();
|
||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||
for (final Entity ent : entities) {
|
||||
if (!(ent instanceof Player)) {
|
||||
ent.remove();
|
||||
}
|
||||
}
|
||||
PS.debug("[PlotSquared] &a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
||||
}
|
||||
if (tiles.length > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) {
|
||||
if (unload) {
|
||||
PS.debug("[PlotSquared] &c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
||||
cleanChunk(chunk);
|
||||
return true;
|
||||
}
|
||||
for (final BlockState tile : tiles) {
|
||||
tile.getBlock().setType(Material.AIR, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ForceFieldListener implements Listener {
|
||||
private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) {
|
||||
final Set<PlotPlayer> players = new HashSet<>();
|
||||
PlotPlayer pp;
|
||||
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
||||
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
if (!plot.isAdded(pp.getUUID())) {
|
||||
players.add(pp);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
private PlotPlayer hasNearbyPermitted(final Player player, final Plot plot) {
|
||||
PlotPlayer pp;
|
||||
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
||||
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
||||
continue;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID())) {
|
||||
return pp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector calculateVelocity(final PlotPlayer pp, final PlotPlayer e) {
|
||||
Location playerLocation = pp.getLocationFull();
|
||||
Location oPlayerLocation = e.getLocation();
|
||||
final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation
|
||||
.getZ();
|
||||
double x = 0d, y = 0d, z = 0d;
|
||||
if (playerX < oPlayerX) {
|
||||
x = 1.0d;
|
||||
} else if (playerX > oPlayerX) {
|
||||
x = -1.0d;
|
||||
}
|
||||
if (playerY < oPlayerY) {
|
||||
y = 0.5d;
|
||||
} else if (playerY > oPlayerY) {
|
||||
y = -0.5d;
|
||||
}
|
||||
if (playerZ < oPlayerZ) {
|
||||
z = 1.0d;
|
||||
} else if (playerZ > oPlayerZ) {
|
||||
z = -1.0d;
|
||||
}
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlotEntry(final PlayerEnterPlotEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
final Plot plot = event.getPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) {
|
||||
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) {
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (plot.isAdded(uuid)) {
|
||||
final Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||
for (final PlotPlayer oPlayer : players) {
|
||||
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer));
|
||||
}
|
||||
} else {
|
||||
final PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
|
||||
if (oPlayer == null) {
|
||||
return;
|
||||
}
|
||||
player.setVelocity(calculateVelocity(oPlayer, pp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,155 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.listener.PlotListener;
|
||||
|
||||
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event.isShiftClick()) {
|
||||
return;
|
||||
}
|
||||
final HumanEntity entity = event.getWhoClicked();
|
||||
if (!(entity instanceof Player) || !PS.get().hasPlotArea(entity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) entity;
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
final int slot = inv.getHeldItemSlot();
|
||||
if ((slot != event.getSlot()) || (slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
|
||||
return;
|
||||
}
|
||||
final ItemStack current = inv.getItemInHand();
|
||||
final ItemStack newItem = event.getCursor();
|
||||
final ItemMeta newMeta = newItem.getItemMeta();
|
||||
final ItemMeta oldMeta = newItem.getItemMeta();
|
||||
String newLore = "";
|
||||
if (newMeta != null) {
|
||||
final List<String> lore = newMeta.getLore();
|
||||
if (lore != null) {
|
||||
newLore = lore.toString();
|
||||
}
|
||||
}
|
||||
String oldLore = "";
|
||||
if (oldMeta != null) {
|
||||
final List<String> lore = oldMeta.getLore();
|
||||
if (lore != null) {
|
||||
oldLore = lore.toString();
|
||||
}
|
||||
}
|
||||
if (!newLore.equals("[(+NBT)]") || (current.equals(newItem) && newLore.equals(oldLore))) {
|
||||
return;
|
||||
}
|
||||
final HashSet<Byte> blocks = null;
|
||||
final Block block = player.getTargetBlock(blocks, 7);
|
||||
final BlockState state = block.getState();
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
if (state.getType() != newItem.getType()) {
|
||||
return;
|
||||
}
|
||||
final Location l = BukkitUtil.getLocation(state.getLocation());
|
||||
PlotArea area = l.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
final Plot plot = area.getPlotAbs(l);
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
boolean cancelled = false;
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
||||
cancelled = true;
|
||||
}
|
||||
} else {
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
||||
cancelled = true;
|
||||
}
|
||||
} else {
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (!plot.isAdded(uuid)) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cancelled) {
|
||||
if ((current.getTypeId() == newItem.getTypeId()) && (current.getDurability() == newItem.getDurability())) {
|
||||
event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInteract(final PlayerInteractAtEntityEvent e) {
|
||||
final Entity entity = e.getRightClicked();
|
||||
if (!(entity instanceof ArmorStand)) {
|
||||
return;
|
||||
}
|
||||
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
||||
final PlotArea area = l.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
final Plot plot = area.getPlotAbs(l);
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (!plot.isAdded(uuid)) {
|
||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class PlayerEvents_1_8_3 implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(final BlockExplodeEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
Location loc = BukkitUtil.getLocation(block.getLocation());
|
||||
final String world = loc.getWorld();
|
||||
if (!PS.get().hasPlotArea(world)) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = loc.getPlotArea();
|
||||
if (area == null) {
|
||||
final Iterator<Block> iter = event.blockList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
loc = BukkitUtil.getLocation(iter.next().getLocation());
|
||||
if (loc.getPlotArea() != null) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(loc);
|
||||
if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
final Iterator<Block> iter = event.blockList().iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Block b = iter.next();
|
||||
if (!plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation())))) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,269 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.listener.PlotListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created 2014-10-30 for PlotSquared
|
||||
*
|
||||
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public class PlotPlusListener extends PlotListener implements Listener {
|
||||
private final static HashMap<String, Interval> feedRunnable = new HashMap<>();
|
||||
private final static HashMap<String, Interval> healRunnable = new HashMap<>();
|
||||
|
||||
public static void startRunnable(final JavaPlugin plugin) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!healRunnable.isEmpty()) {
|
||||
for (final Iterator<Entry<String, Interval>> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
|
||||
final Entry<String, Interval> entry = iter.next();
|
||||
final Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
final double level = player.getHealth();
|
||||
if (level != value.max) {
|
||||
player.setHealth(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!feedRunnable.isEmpty()) {
|
||||
for (final Iterator<Entry<String, Interval>> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
|
||||
final Entry<String, Interval> entry = iter.next();
|
||||
final Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
final int level = player.getFoodLevel();
|
||||
if (level != value.max) {
|
||||
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0l, 20l);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onMelt(final BlockFadeEvent event) {
|
||||
final BlockState state = event.getNewState();
|
||||
|
||||
if (state.getType() != Material.WATER && state.getType() != Material.STATIONARY_WATER) {
|
||||
return;
|
||||
}
|
||||
final Plot plot = BukkitUtil.getLocation(state.getLocation()).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (!FlagManager.isBooleanFlag(plot, "ice-melt", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInteract(final BlockDamageEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||
return;
|
||||
}
|
||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
|
||||
event.getBlock().breakNaturally();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDamage(final EntityDamageEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) event.getEntity();
|
||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemPickup(final PlayerPickupItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(final PlayerDropItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlotEnter(final PlayerEnterPlotEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Plot plot = event.getPlot();
|
||||
final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
||||
if (feed != null) {
|
||||
final Integer[] value = (Integer[]) feed.getValue();
|
||||
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||
}
|
||||
final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
||||
if (heal != null) {
|
||||
final Integer[] value = (Integer[]) heal.getValue();
|
||||
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName();
|
||||
feedRunnable.remove(name);
|
||||
healRunnable.remove(name);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlotLeave(final PlayerLeavePlotEvent event) {
|
||||
final Player leaver = event.getPlayer();
|
||||
final Plot plot = event.getPlot();
|
||||
if (!plot.hasOwner()) {
|
||||
return;
|
||||
}
|
||||
BukkitUtil.getPlayer(leaver);
|
||||
final String name = leaver.getName();
|
||||
feedRunnable.remove(name);
|
||||
healRunnable.remove(name);
|
||||
}
|
||||
|
||||
public static class Interval {
|
||||
public final int interval;
|
||||
public final int amount;
|
||||
public final int max;
|
||||
public int count = 0;
|
||||
|
||||
public Interval(final int interval, final int amount, final int max) {
|
||||
this.interval = interval;
|
||||
this.amount = amount;
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record Meta Class
|
||||
*
|
||||
|
||||
*/
|
||||
public static class RecordMeta {
|
||||
public final static List<RecordMeta> metaList = new ArrayList<>();
|
||||
static {
|
||||
for (int x = 3; x < 12; x++) {
|
||||
metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
|
||||
}
|
||||
}
|
||||
private final String name;
|
||||
private final Material material;
|
||||
|
||||
public RecordMeta(final String name, final Material material) {
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
|
||||
public class WorldEvents implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public static void onWorldInit(final WorldInitEvent event) {
|
||||
final World world = event.getWorld();
|
||||
final String name = world.getName();
|
||||
final ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof GeneratorWrapper) {
|
||||
PS.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||
} else {
|
||||
PS.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,337 @@
|
||||
package com.plotsquared.bukkit.listeners.worldedit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.listener.WEManager;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
|
||||
public class WEListener implements Listener {
|
||||
|
||||
public final HashSet<String> rad1 = new HashSet<>(Arrays.asList("forestgen", "pumpkins", "drain", "fixwater", "fixlava", "replacenear", "snow", "thaw", "ex", "butcher", "size"));
|
||||
public final HashSet<String> rad2 = new HashSet<>(Arrays.asList("fill", "fillr", "removenear", "remove"));
|
||||
public final HashSet<String> rad2_1 = new HashSet<>(Arrays.asList("hcyl", "cyl"));
|
||||
public final HashSet<String> rad2_2 = new HashSet<>(Arrays.asList("sphere", "pyramid"));
|
||||
public final HashSet<String> rad2_3 = new HashSet<>(Collections.singletonList("brush smooth"));
|
||||
public final HashSet<String> rad3_1 = new HashSet<>(Collections.singletonList("brush gravity"));
|
||||
public final HashSet<String> rad3_2 = new HashSet<>(Arrays.asList("brush sphere", "brush cylinder"));
|
||||
|
||||
public final HashSet<String> region = new HashSet<>(Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr",
|
||||
"regen", "copy", "cut", "green", "setbiome"));
|
||||
public final HashSet<String> regionExtend = new HashSet<>(Collections.singletonList("stack"));
|
||||
public final HashSet<String> unregioned = new HashSet<>(Arrays.asList("paste", "redo", "undo", "rotate", "flip", "generate", "schematic", "schem"));
|
||||
public final HashSet<String> unsafe1 = new HashSet<>(Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks"));
|
||||
public final HashSet<String> restricted = new HashSet<>(Collections.singletonList("up"));
|
||||
public final HashSet<String> other = new HashSet<>(Arrays.asList("undo", "redo"));
|
||||
|
||||
public boolean checkCommand(final List<String> list, final String cmd) {
|
||||
for (final String identifier : list) {
|
||||
if (("/" + identifier).equals(cmd) || ("//" + identifier).equals(cmd) || ("/worldedit:/" + identifier).equals(cmd) || ("/worldedit:" + identifier).equals(cmd)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String reduceCmd(final String cmd, final boolean single) {
|
||||
if (cmd.startsWith("/worldedit:/")) {
|
||||
return cmd.substring(12);
|
||||
}
|
||||
if (cmd.startsWith("/worldedit:")) {
|
||||
return cmd.substring(11);
|
||||
}
|
||||
if (cmd.startsWith("//")) {
|
||||
return cmd.substring(2);
|
||||
}
|
||||
if (single && cmd.startsWith("/")) {
|
||||
return cmd.substring(1);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public int getInt(final String s) {
|
||||
try {
|
||||
int max = 0;
|
||||
final String[] split = s.split(",");
|
||||
for (final String rad : split) {
|
||||
final int val = Integer.parseInt(rad);
|
||||
if (val > max) {
|
||||
max = val;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
} catch (final NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkVolume(final PlotPlayer player, final long volume, final long max, final Cancellable e) {
|
||||
if (volume > max) {
|
||||
MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", volume + "").replaceAll("%max%", max + ""));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkSelection(final Player p, final PlotPlayer pp, final int modifier, final long max, final Cancellable e) {
|
||||
final Selection selection = BukkitMain.worldEdit.getSelection(p);
|
||||
if (selection == null) {
|
||||
return true;
|
||||
}
|
||||
final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector();
|
||||
final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector();
|
||||
final HashSet<RegionWrapper> mask = WEManager.getMask(pp);
|
||||
final RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
|
||||
if (Settings.REQUIRE_SELECTION) {
|
||||
String arg = null;
|
||||
if (!WEManager.regionContains(region, mask)) {
|
||||
arg = "pos1 + pos2";
|
||||
} else if (!WEManager.maskContains(mask, pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ())) {
|
||||
arg = "pos1";
|
||||
} else if (!WEManager.maskContains(mask, pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ())) {
|
||||
arg = "pos2";
|
||||
}
|
||||
if (arg != null) {
|
||||
e.setCancelled(true);
|
||||
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, arg);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!WEManager.regionContains(region, mask)) {
|
||||
MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "pos1 + pos2");
|
||||
e.setCancelled(true);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final long volume = Math.abs((pos1.getBlockX() - pos2.getBlockX()) * (pos1.getBlockY() - pos2.getBlockY()) * (pos1.getBlockZ() - pos2.getBlockZ())) * modifier;
|
||||
return checkVolume(pp, volume, max, e);
|
||||
}
|
||||
|
||||
public boolean delay(final Player player, final String command, final boolean delayed) {
|
||||
if (!Settings.QUEUE_COMMANDS || !Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
||||
return false;
|
||||
}
|
||||
final boolean free = SetQueue.IMP.addTask(null);
|
||||
if (free) {
|
||||
if (delayed) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.WORLDEDIT_RUN, command);
|
||||
Bukkit.getServer().dispatchCommand(player, command.substring(1));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!delayed) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.WORLDEDIT_DELAYED);
|
||||
}
|
||||
SetQueue.IMP.addTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delay(player, command, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public boolean onPlayerCommand(final PlayerCommandPreprocessEvent e) {
|
||||
final WorldEditPlugin worldedit = BukkitMain.worldEdit;
|
||||
if (worldedit == null) {
|
||||
HandlerList.unregisterAll(this);
|
||||
return true;
|
||||
}
|
||||
final Player p = e.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||
if (!PS.get().hasPlotArea(p.getWorld().getName())) {
|
||||
return true;
|
||||
}
|
||||
final String message = e.getMessage();
|
||||
final String cmd = message.toLowerCase();
|
||||
final boolean single = true;
|
||||
final String[] split = cmd.split(" ");
|
||||
|
||||
final long maxVolume = Settings.WE_MAX_VOLUME;
|
||||
final long maxIterations = Settings.WE_MAX_ITERATIONS;
|
||||
if (pp.getAttribute("worldedit")) {
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 2) {
|
||||
final String reduced = reduceCmd(split[0], single);
|
||||
final String reduced2 = reduceCmd(split[0] + " " + split[1], single);
|
||||
if (rad1.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
final long volume = getInt(split[1]) * 256;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
if (rad2.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 3) {
|
||||
final long volume = getInt(split[2]) * 256;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (rad2_1.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 4) {
|
||||
final long volume = getInt(split[2]) * getInt(split[3]);
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (rad2_2.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 3) {
|
||||
final long radius = getInt(split[2]);
|
||||
final long volume = radius * radius;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (rad2_3.contains(reduced2)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 3) {
|
||||
if (split.length == 4) {
|
||||
final int iterations = getInt(split[3]);
|
||||
if (iterations > maxIterations) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", iterations + "").replaceAll("%max%", maxIterations + ""));
|
||||
e.setCancelled(true);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final long radius = getInt(split[2]);
|
||||
final long volume = radius * radius;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (rad3_1.contains(reduced2)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 3) {
|
||||
int i = 2;
|
||||
if (split[i].equalsIgnoreCase("-h")) {
|
||||
i = 3;
|
||||
}
|
||||
final long radius = getInt(split[i]);
|
||||
final long volume = radius * radius;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (rad3_2.contains(reduced2)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
if (split.length >= 4) {
|
||||
int i = 3;
|
||||
if (split[i].equalsIgnoreCase("-h")) {
|
||||
i = 4;
|
||||
}
|
||||
final long radius = getInt(split[i]);
|
||||
final long volume = radius * radius;
|
||||
return checkVolume(pp, volume, maxVolume, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (regionExtend.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
return checkSelection(p, pp, getInt(split[1]), maxVolume, e);
|
||||
}
|
||||
}
|
||||
final String reduced = reduceCmd(split[0], single);
|
||||
if (Settings.WE_BLACKLIST.contains(reduced)) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE);
|
||||
e.setCancelled(true);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
}
|
||||
if (restricted.contains(reduced)) {
|
||||
final Plot plot = pp.getCurrentPlot();
|
||||
if ((plot != null) && plot.isAdded(pp.getUUID())) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
MainUtil.sendMessage(pp, C.NO_PLOT_PERMS);
|
||||
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (region.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
return checkSelection(p, pp, 1, maxVolume, e);
|
||||
}
|
||||
if (other.contains(reduced)) {
|
||||
if (delay(p, message, false)) {
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.managers;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Default Bukkit world manager. It will handle world creation by
|
||||
* registering the generator in bukkit.yml
|
||||
*/
|
||||
@Singleton
|
||||
public class BukkitWorldManager implements PlatformWorldManager<World> {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable World handleWorldCreation(@NonNull String worldName, @Nullable String generator) {
|
||||
this.setGenerator(worldName, generator);
|
||||
final WorldCreator wc = new WorldCreator(worldName);
|
||||
wc.environment(World.Environment.NORMAL);
|
||||
if (generator != null) {
|
||||
wc.generator(generator);
|
||||
wc.type(WorldType.FLAT);
|
||||
}
|
||||
return Bukkit.createWorld(wc);
|
||||
}
|
||||
|
||||
protected void setGenerator(final @Nullable String worldName, final @Nullable String generator) {
|
||||
if (generator == null) {
|
||||
return;
|
||||
}
|
||||
File file = new File("bukkit.yml").getAbsoluteFile();
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
yml.set(String.format("worlds.%s.generator", worldName), generator);
|
||||
try {
|
||||
yml.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "bukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getWorlds() {
|
||||
final List<World> worlds = Bukkit.getWorlds();
|
||||
final List<String> worldNames = new ArrayList<>();
|
||||
for (final World world : worlds) {
|
||||
worldNames.add(world.getName());
|
||||
}
|
||||
return worldNames;
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.managers;
|
||||
|
||||
/*
|
||||
import com.google.inject.Singleton;
|
||||
import org.bukkit.World;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import se.hyperver.hyperverse.Hyperverse;
|
||||
import se.hyperver.hyperverse.world.WorldConfiguration;
|
||||
import se.hyperver.hyperverse.world.WorldConfigurationBuilder;
|
||||
import se.hyperver.hyperverse.world.WorldFeatures;
|
||||
import se.hyperver.hyperverse.world.WorldType;
|
||||
|
||||
Hyperverse implementation is currently put on ice until Hyperverse is released on a stable line and deployed to the central
|
||||
repository.
|
||||
|
||||
@Singleton
|
||||
public class HyperverseWorldManager extends BukkitWorldManager {
|
||||
|
||||
@Override
|
||||
public @Nullable World handleWorldCreation(@NonNull String worldName, @Nullable String generator) {
|
||||
// First let Bukkit register the world
|
||||
this.setGenerator(worldName, generator);
|
||||
// Create the world
|
||||
final WorldConfigurationBuilder worldConfigurationBuilder = WorldConfiguration.builder()
|
||||
.setName(worldName).setType(WorldType.OVER_WORLD);
|
||||
if (generator != null) {
|
||||
worldConfigurationBuilder.setGenerator(generator).setWorldFeatures(WorldFeatures.FLATLAND);
|
||||
}
|
||||
try {
|
||||
return Hyperverse.getApi().createWorld(worldConfigurationBuilder.createWorldConfiguration())
|
||||
.getBukkitWorld();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "bukkit-hyperverse";
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* PlotSquared, a land and world management plugin for Minecraft.
|
||||
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
||||
* Copyright (C) IntellectualSites team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.managers;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Multiverse specific manager that informs Multiverse of
|
||||
* world creation by executing a console command
|
||||
*
|
||||
* @deprecated Deprecated and scheduled for removal without replacement
|
||||
* in favor of the build in setup wizard.
|
||||
* However, this class will be kept around for a while, given it's not a maintenance burden.
|
||||
*/
|
||||
@Deprecated
|
||||
@Singleton
|
||||
public class MultiverseWorldManager extends BukkitWorldManager {
|
||||
|
||||
@Override
|
||||
public @Nullable World handleWorldCreation(final @NonNull String worldName, final @Nullable String generator) {
|
||||
// First let Bukkit register the world
|
||||
this.setGenerator(worldName, generator);
|
||||
// Then we send the console command
|
||||
final StringBuilder commandBuilder = new StringBuilder("mv create ")
|
||||
.append(worldName).append(" normal");
|
||||
if (generator != null) {
|
||||
commandBuilder.append(" -g ").append(generator);
|
||||
}
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), commandBuilder.toString());
|
||||
return Bukkit.getWorld(worldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "bukkit-multiverse";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.intellectualcrafters.plot.object.LazyBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
|
||||
public class BukkitLazyBlock extends LazyBlock {
|
||||
|
||||
private int id;
|
||||
private Block block;
|
||||
private PlotBlock pb;
|
||||
|
||||
public BukkitLazyBlock(final int id, final Block block) {
|
||||
this.id = id;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BukkitLazyBlock(final PlotBlock pb) {
|
||||
id = pb.id;
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
public BukkitLazyBlock(final Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getPlotBlock() {
|
||||
if (pb != null) {
|
||||
return pb;
|
||||
}
|
||||
if (id == 0) {
|
||||
id = block.getTypeId();
|
||||
}
|
||||
byte data;
|
||||
switch (id) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 24:
|
||||
case 25:
|
||||
case 30:
|
||||
case 32:
|
||||
case 37:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 51:
|
||||
case 52:
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 60:
|
||||
case 61:
|
||||
case 62:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 73:
|
||||
case 74:
|
||||
case 78:
|
||||
case 79:
|
||||
case 80:
|
||||
case 81:
|
||||
case 82:
|
||||
case 83:
|
||||
case 84:
|
||||
case 85:
|
||||
case 87:
|
||||
case 88:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 110:
|
||||
case 112:
|
||||
case 113:
|
||||
case 117:
|
||||
case 121:
|
||||
case 122:
|
||||
case 123:
|
||||
case 124:
|
||||
case 129:
|
||||
case 133:
|
||||
case 138:
|
||||
case 137:
|
||||
case 140:
|
||||
case 165:
|
||||
case 166:
|
||||
case 169:
|
||||
case 170:
|
||||
case 172:
|
||||
case 173:
|
||||
case 174:
|
||||
case 176:
|
||||
case 177:
|
||||
case 181:
|
||||
case 182:
|
||||
case 188:
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
data = 0;
|
||||
break;
|
||||
default:
|
||||
data = block.getData();
|
||||
break;
|
||||
}
|
||||
pb = new PlotBlock((short) id, data);
|
||||
return pb;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (id == 0) {
|
||||
id = block.getTypeId();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
|
||||
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
|
||||
public final OfflinePlayer player;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||
* @param player
|
||||
*/
|
||||
public BukkitOfflinePlayer(final OfflinePlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
return player.getLastPlayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.WeatherType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
public boolean offline;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private long last = 0;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||
* @param player
|
||||
*/
|
||||
public BukkitPlayer(final Player player) {
|
||||
this.player = player;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
|
||||
public BukkitPlayer(final Player player, final boolean offline) {
|
||||
this.player = player;
|
||||
this.offline = offline;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPreviousLogin() {
|
||||
if (last == 0) {
|
||||
last = player.getLastPlayed();
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
final Location loc = super.getLocation();
|
||||
return loc == null ? BukkitUtil.getLocation(player) : loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String node) {
|
||||
if (offline && EconHandler.manager != null) {
|
||||
return EconHandler.manager.hasPermission(getName(), node);
|
||||
}
|
||||
return player.hasPermission(node);
|
||||
}
|
||||
|
||||
public Permission getPermission(final String node) {
|
||||
final PluginManager manager = Bukkit.getPluginManager();
|
||||
Permission perm = manager.getPermission(node);
|
||||
if (perm == null) {
|
||||
final String[] nodes = node.split("\\.");
|
||||
perm = new Permission(node);
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < nodes.length - 1; i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (!node.equals(n + C.PERMISSION_STAR.s())) {
|
||||
final Permission parent = getPermission(n + C.PERMISSION_STAR.s());
|
||||
if (parent != null) {
|
||||
perm.addParent(parent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
manager.addPermission(perm);
|
||||
}
|
||||
manager.recalculatePermissionDefaults(perm);
|
||||
perm.recalculatePermissibles();
|
||||
return perm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc) {
|
||||
if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) {
|
||||
return;
|
||||
}
|
||||
player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()), TeleportCause.COMMAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
name = player.getName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return !offline && player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc) {
|
||||
player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocationFull() {
|
||||
return BukkitUtil.getLocationFull(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
if (!player.isOnline()) {
|
||||
player.loadData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
player.saveData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(final PlotWeather weather) {
|
||||
switch (weather) {
|
||||
case CLEAR:
|
||||
player.setPlayerWeather(WeatherType.CLEAR);
|
||||
return;
|
||||
case RAIN:
|
||||
player.setPlayerWeather(WeatherType.DOWNFALL);
|
||||
return;
|
||||
case RESET:
|
||||
player.resetPlayerWeather();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotGamemode getGamemode() {
|
||||
switch (player.getGameMode()) {
|
||||
case ADVENTURE:
|
||||
return PlotGamemode.ADVENTURE;
|
||||
case CREATIVE:
|
||||
return PlotGamemode.CREATIVE;
|
||||
case SPECTATOR:
|
||||
return PlotGamemode.SPECTATOR;
|
||||
case SURVIVAL:
|
||||
return PlotGamemode.SURVIVAL;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGamemode(final PlotGamemode gamemode) {
|
||||
switch (gamemode) {
|
||||
case ADVENTURE:
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
return;
|
||||
case CREATIVE:
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
return;
|
||||
case SPECTATOR:
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
return;
|
||||
case SURVIVAL:
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(final long time) {
|
||||
if (time != Long.MAX_VALUE) {
|
||||
player.setPlayerTime(time, false);
|
||||
} else {
|
||||
player.resetPlayerTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlight(final boolean fly) {
|
||||
player.setAllowFlight(fly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMusic(final Location loc, final int id) {
|
||||
player.playEffect(BukkitUtil.getLocation(loc), Effect.RECORD_PLAY, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(final String message) {
|
||||
player.kickPlayer(message);
|
||||
}
|
||||
|
||||
@Override public void stopSpectating() {
|
||||
if (getGamemode() == PlotGamemode.SPECTATOR) {
|
||||
player.setSpectatorTarget(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
return player.isBanned();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.plotsquared.bukkit.object.entity;
|
||||
|
||||
public class AgeableStats {
|
||||
public int age;
|
||||
public boolean locked;
|
||||
public boolean adult;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.plotsquared.bukkit.object.entity;
|
||||
|
||||
public class ArmorStandStats {
|
||||
public float[] head = new float[3];
|
||||
public float[] body = new float[3];
|
||||
public float[] leftLeg = new float[3];
|
||||
public float[] rightLeg = new float[3];
|
||||
public float[] leftArm = new float[3];
|
||||
public float[] rightArm = new float[3];
|
||||
public boolean arms;
|
||||
public boolean noplate;
|
||||
public boolean nogravity;
|
||||
public boolean invisible;
|
||||
public boolean small;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.plotsquared.bukkit.object.entity;
|
||||
|
||||
|
||||
public class EntityBaseStats {
|
||||
public EntityWrapper passenger;
|
||||
public float fall;
|
||||
public short fire;
|
||||
public int age;
|
||||
public double v_z;
|
||||
public double v_y;
|
||||
public double v_x;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user