From c667a49c9c7740330db31862e5d3618ea0868d43 Mon Sep 17 00:00:00 2001 From: darksaid98 Date: Mon, 23 Oct 2023 01:48:07 +0200 Subject: [PATCH] style: reformat and .editorconfig --- .editorconfig | 435 ++++++ .../siegeengines/EquipmentMagazine.java | 6 +- .../alathra/siegeengines/GunnerEquipment.java | 443 +++--- .../alathra/siegeengines/SiegeEngines.java | 724 +++++----- .../siegeengines/listeners/ClickHandler.java | 1235 ++++++++--------- .../listeners/RotationHandler.java | 136 +- .../projectile/EntityProjectile.java | 139 +- .../projectile/ExplosiveProjectile.java | 123 +- .../projectile/GunnersProjectile.java | 5 +- .../projectile/PotionProjectile.java | 105 +- src/main/resources/plugin.yml | 10 +- 11 files changed, 1893 insertions(+), 1468 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bed2d93 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,435 @@ +root = true + +[*] +charset = utf-8 +end_of_line = crlf +indent_size = 4 +indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 4 +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = +ij_wrap_on_typing = false + +[*.java] +ij_continuation_indent_size = 4 +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_deconstruction_list_components = true +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_align_types_in_multi_catch = true +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 = 0 +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 = 0 +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_add_space = false +ij_java_block_comment_at_first_column = true +ij_java_builder_methods = +ij_java_call_parameters_new_line_after_left_paren = false +ij_java_call_parameters_right_paren_on_new_line = false +ij_java_call_parameters_wrap = off +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 = 5 +ij_java_class_names_in_javadoc = 1 +ij_java_deconstruction_list_wrap = normal +ij_java_do_not_indent_top_level_class_members = false +ij_java_do_not_wrap_after_single_annotation = false +ij_java_do_not_wrap_after_single_annotation_in_parameter = false +ij_java_do_while_brace_force = never +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 = false +ij_java_doc_keep_empty_lines = true +ij_java_doc_keep_empty_parameter_tag = true +ij_java_doc_keep_empty_return_tag = true +ij_java_doc_keep_empty_throws_tag = true +ij_java_doc_keep_invalid_tags = true +ij_java_doc_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 = off +ij_java_extends_keyword_wrap = off +ij_java_extends_list_wrap = off +ij_java_field_annotation_wrap = split_into_lines +ij_java_field_name_prefix = +ij_java_field_name_suffix = +ij_java_finally_on_new_line = false +ij_java_for_brace_force = never +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 = false +ij_java_generate_final_parameters = false +ij_java_if_brace_force = never +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_builder_methods_indents = false +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_add_space_on_reformat = false +ij_java_line_comment_at_first_column = true +ij_java_local_variable_name_prefix = +ij_java_local_variable_name_suffix = +ij_java_method_annotation_wrap = split_into_lines +ij_java_method_brace_style = end_of_line +ij_java_method_call_chain_wrap = off +ij_java_method_parameters_new_line_after_left_paren = false +ij_java_method_parameters_right_paren_on_new_line = false +ij_java_method_parameters_wrap = off +ij_java_modifier_list_wrap = false +ij_java_multi_catch_types_wrap = normal +ij_java_names_count_to_use_import_on_demand = 3 +ij_java_new_line_after_lparen_in_annotation = false +ij_java_new_line_after_lparen_in_deconstruction_pattern = true +ij_java_new_line_after_lparen_in_record_header = false +ij_java_packages_to_use_import_on_demand = java.awt.*, javax.swing.* +ij_java_parameter_annotation_wrap = off +ij_java_parameter_name_prefix = +ij_java_parameter_name_suffix = +ij_java_parentheses_expression_new_line_after_left_paren = false +ij_java_parentheses_expression_right_paren_on_new_line = false +ij_java_place_assignment_sign_on_next_line = false +ij_java_prefer_longer_names = true +ij_java_prefer_parameters_wrap = false +ij_java_record_components_wrap = normal +ij_java_repeat_annotations = +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_annotation = false +ij_java_rparen_on_new_line_in_deconstruction_pattern = true +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_deconstruction_list = 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_annotation_eq = 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_deconstruction_list = 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_record_header = 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_static_field_name_prefix = +ij_java_static_field_name_suffix = +ij_java_subclass_name_prefix = +ij_java_subclass_name_suffix = Impl +ij_java_ternary_operation_signs_on_next_line = false +ij_java_ternary_operation_wrap = off +ij_java_test_name_prefix = +ij_java_test_name_suffix = Test +ij_java_throws_keyword_wrap = off +ij_java_throws_list_wrap = off +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 = never +ij_java_while_on_new_line = false +ij_java_wrap_comments = false +ij_java_wrap_first_method_in_call_chain = false +ij_java_wrap_long_lines = false + +[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.jspx,*.pom,*.rng,*.tagx,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}] +ij_continuation_indent_size = 4 +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = normal +ij_xml_block_comment_add_space = false +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false +ij_xml_space_around_equals_in_attribute = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal + +[{*.gradle.kts,*.kt,*.kts,*.main.kts,*.space.kts}] +ij_continuation_indent_size = 4 +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_add_space = false +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_imports_layout = *, java.**, javax.**, kotlin.**, ^ +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_break_after_multiline_when_entry = true +ij_kotlin_line_comment_add_space = false +ij_kotlin_line_comment_add_space_on_reformat = 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_packages_to_use_import_on_demand = java.util.*, kotlinx.android.synthetic.**, io.ktor.** +ij_kotlin_parameter_annotation_wrap = off +ij_kotlin_space_after_comma = true +ij_kotlin_space_after_extend_colon = true +ij_kotlin_space_after_type_colon = true +ij_kotlin_space_before_catch_parentheses = true +ij_kotlin_space_before_comma = false +ij_kotlin_space_before_extend_colon = true +ij_kotlin_space_before_for_parentheses = true +ij_kotlin_space_before_if_parentheses = true +ij_kotlin_space_before_lambda_arrow = true +ij_kotlin_space_before_type_colon = false +ij_kotlin_space_before_when_parentheses = true +ij_kotlin_space_before_while_parentheses = true +ij_kotlin_spaces_around_additive_operators = true +ij_kotlin_spaces_around_assignment_operators = true +ij_kotlin_spaces_around_equality_operators = true +ij_kotlin_spaces_around_function_type_arrow = true +ij_kotlin_spaces_around_logical_operators = true +ij_kotlin_spaces_around_multiplicative_operators = true +ij_kotlin_spaces_around_range = false +ij_kotlin_spaces_around_relational_operators = true +ij_kotlin_spaces_around_unary_operator = false +ij_kotlin_spaces_around_when_arrow = true +ij_kotlin_variable_annotation_wrap = off +ij_kotlin_while_on_new_line = false +ij_kotlin_wrap_elvis_expressions = 1 +ij_kotlin_wrap_expression_body_functions = 0 +ij_kotlin_wrap_first_method_in_call_chain = false + +[{*.har,*.json,*.png.mcmeta,mcmod.info,pack.mcmeta}] +indent_size = 2 +ij_continuation_indent_size = 4 +ij_json_array_wrapping = split_into_lines +ij_json_keep_blank_lines_in_code = 0 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_line_breaks = true +ij_json_keep_trailing_comma = false +ij_json_object_wrapping = split_into_lines +ij_json_property_alignment = do_not_align +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = false +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false + +[{*.markdown,*.md,*.md }] +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_format_tables = true +ij_markdown_insert_quote_arrows_on_wrap = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_keep_line_breaks_inside_text_blocks = true +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 +ij_markdown_wrap_text_if_long = true +ij_markdown_wrap_text_inside_blockquotes = true + +[{*.toml,Cargo.lock,Cargo.toml.orig,Gopkg.lock,Pipfile,poetry.lock}] +ij_continuation_indent_size = 4 +ij_toml_keep_indents_on_empty_lines = false + +[{*.yaml,*.yml}] +indent_size = 2 +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true \ No newline at end of file diff --git a/src/main/java/com/github/alathra/siegeengines/EquipmentMagazine.java b/src/main/java/com/github/alathra/siegeengines/EquipmentMagazine.java index 8c950a5..0c4b5bd 100644 --- a/src/main/java/com/github/alathra/siegeengines/EquipmentMagazine.java +++ b/src/main/java/com/github/alathra/siegeengines/EquipmentMagazine.java @@ -4,7 +4,7 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class EquipmentMagazine { - public int LoadedFuel = 0; - public int LoadedProjectile = 0; - public ItemStack MaterialName = new ItemStack(Material.AIR, 1); + public int LoadedFuel = 0; + public int LoadedProjectile = 0; + public ItemStack MaterialName = new ItemStack(Material.AIR, 1); } diff --git a/src/main/java/com/github/alathra/siegeengines/GunnerEquipment.java b/src/main/java/com/github/alathra/siegeengines/GunnerEquipment.java index 5e361c2..7632373 100644 --- a/src/main/java/com/github/alathra/siegeengines/GunnerEquipment.java +++ b/src/main/java/com/github/alathra/siegeengines/GunnerEquipment.java @@ -22,261 +22,258 @@ import org.bukkit.util.Vector; //import me.libraryaddict.disguise.disguisetypes.DisguiseType; //import me.libraryaddict.disguise.disguisetypes.MiscDisguise; -public class GunnerEquipment implements Cloneable { +public class GunnerEquipment implements Cloneable { - @Override - public GunnerEquipment clone() throws CloneNotSupportedException { - return (GunnerEquipment)super.clone(); - } - public Boolean Enabled = true; - public UUID EntityId; - public Entity Entity; - public Integer shotAmount = 1; + @Override + public GunnerEquipment clone() throws CloneNotSupportedException { + return (GunnerEquipment) super.clone(); + } - public HashMap Projectiles = new HashMap(); + public Boolean Enabled = true; + public UUID EntityId; + public Entity Entity; + public Integer shotAmount = 1; - public String WorldName; - public String EquipmentName = "Peckle Gun"; - public int XOffset = 7; - public int YOffset = 0; - public int PitchOffset = 0; - public int MaxFuel = 5; - public double PlacementOffsetY = 0; - public float VelocityPerFuel = 1.75f; - public ItemStack FuelMaterial = new ItemStack(Material.GUNPOWDER); - public long NextShotTime = System.currentTimeMillis(); + public HashMap Projectiles = new HashMap(); - public int MillisecondsBetweenFiringStages; - public int MillisecondsBetweenReloadingStages; + public String WorldName; + public String EquipmentName = "Peckle Gun"; + public int XOffset = 7; + public int YOffset = 0; + public int PitchOffset = 0; + public int MaxFuel = 5; + public double PlacementOffsetY = 0; + public float VelocityPerFuel = 1.75f; + public ItemStack FuelMaterial = new ItemStack(Material.GUNPOWDER); + public long NextShotTime = System.currentTimeMillis(); - public int MillisecondsToLoad; - public int ModelNumberToFireAt; - public Boolean CycleThroughModelsBeforeFiring = false; - public Boolean RotateSideways = false; - public Boolean RotateUpDown = true; - public Boolean RotateStandHead = true; - public Boolean HasFired = false; - public Boolean HasReloaded = false; - public Boolean AllowInvisibleStand = false; - public Boolean HaseBaseStand = false; - public double BaseStandOffset = 0; - public int BaseStandModelNumber = 147; - public int TaskNumber; + public int MillisecondsBetweenFiringStages; + public int MillisecondsBetweenReloadingStages; - public int ReadyModelNumber; + public int MillisecondsToLoad; + public int ModelNumberToFireAt; + public Boolean CycleThroughModelsBeforeFiring = false; + public Boolean RotateSideways = false; + public Boolean RotateUpDown = true; + public Boolean RotateStandHead = true; + public Boolean HasFired = false; + public Boolean HasReloaded = false; + public Boolean AllowInvisibleStand = false; + public Boolean HaseBaseStand = false; + public double BaseStandOffset = 0; + public int BaseStandModelNumber = 147; + public int TaskNumber; - public int NextModelNumber = 0; + public int ReadyModelNumber; - public List FiringModelNumbers = new ArrayList(); + public int NextModelNumber = 0; - public EquipmentMagazine AmmoHolder = new EquipmentMagazine(); + public List FiringModelNumbers = new ArrayList(); - public Boolean isLoaded() { - if (this.MaxFuel <= 0 && AmmoHolder.LoadedProjectile >= 1) - return true; - return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1); - } + public EquipmentMagazine AmmoHolder = new EquipmentMagazine(); - public Boolean CanLoadFuel() { - return AmmoHolder.LoadedFuel < MaxFuel; - } + public Boolean isLoaded() { + if (this.MaxFuel <= 0 && AmmoHolder.LoadedProjectile >= 1) + return true; + return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1); + } - public Boolean LoadFuel(Entity player) { - ItemStack fuelItem = this.FuelMaterial; - if (this.AmmoHolder.LoadedFuel == this.MaxFuel) { - return true; - } - if (!(player instanceof Player)) { - this.AmmoHolder.LoadedFuel = this.MaxFuel; - return true; - } - if (((Player)player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) { - if (CanLoadFuel()) { - this.AmmoHolder.LoadedFuel += 1; - SaveState(); - ((Player)player).getInventory().removeItem(fuelItem); - ((Player)player).sendMessage("§eLoaded " + this.AmmoHolder.LoadedFuel + "/" + this.MaxFuel); - return true; - } - else { - return false; - } - } + public Boolean CanLoadFuel() { + return AmmoHolder.LoadedFuel < MaxFuel; + } - return false; + public Boolean LoadFuel(Entity player) { + ItemStack fuelItem = this.FuelMaterial; + if (this.AmmoHolder.LoadedFuel == this.MaxFuel) { + return true; + } + if (!(player instanceof Player)) { + this.AmmoHolder.LoadedFuel = this.MaxFuel; + return true; + } + if (((Player) player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) { + if (CanLoadFuel()) { + this.AmmoHolder.LoadedFuel += 1; + SaveState(); + ((Player) player).getInventory().removeItem(fuelItem); + ((Player) player).sendMessage("§eLoaded " + this.AmmoHolder.LoadedFuel + "/" + this.MaxFuel); + return true; + } else { + return false; + } + } - } + return false; - public Boolean LoadProjectile(Entity player, ItemStack itemInHand) { - if (itemInHand.getAmount() <= 0) { - return false; - } - if (!(player instanceof Player)) { - this.AmmoHolder.LoadedProjectile = 1; - this.AmmoHolder.LoadedFuel = this.MaxFuel; - this.AmmoHolder.MaterialName = itemInHand; - return true; - } - if (this.Projectiles.containsKey(itemInHand.getType()) && this.AmmoHolder.LoadedProjectile == 0){ - this.AmmoHolder.LoadedProjectile = 1; - this.AmmoHolder.MaterialName = itemInHand; - ((Player)player).sendMessage("§eAdding Ammo to Weapon"); - itemInHand.setAmount(itemInHand.getAmount() - 1); - return true; - } - return false; - } - - public void SaveState() { + } - } + public Boolean LoadProjectile(Entity player, ItemStack itemInHand) { + if (itemInHand.getAmount() <= 0) { + return false; + } + if (!(player instanceof Player)) { + this.AmmoHolder.LoadedProjectile = 1; + this.AmmoHolder.LoadedFuel = this.MaxFuel; + this.AmmoHolder.MaterialName = itemInHand; + return true; + } + if (this.Projectiles.containsKey(itemInHand.getType()) && this.AmmoHolder.LoadedProjectile == 0) { + this.AmmoHolder.LoadedProjectile = 1; + this.AmmoHolder.MaterialName = itemInHand; + ((Player) player).sendMessage("§eAdding Ammo to Weapon"); + itemInHand.setAmount(itemInHand.getAmount() - 1); + return true; + } + return false; + } + + public void SaveState() { + + } - public Location GetFireLocation(LivingEntity living) { - Location loc = living.getEyeLocation(); - Vector direction = living.getLocation().getDirection().multiply(XOffset); - loc.add(direction); - if (this.YOffset > 0) { - loc.setY(loc.getY() + this.YOffset); - } - else { - loc.setY(loc.getY() - this.YOffset); - } - loc.setPitch(loc.getPitch() + this.PitchOffset); - return loc; - } - - public void ShowFireLocation(Entity player) { - LivingEntity living = (LivingEntity) this.Entity; - if (player instanceof Player) { - if (living != null) { - Location origin = this.GetFireLocation(living); - Vector direction = origin.getDirection(); - direction.multiply(5 /* the range */); - Location destination = origin.clone().add(direction); - - direction.normalize(); - for (int i = 0; i < 3 /* range */; i+= 1) { - Location spawn = origin.add(direction); - ((Player)player).spawnParticle(Particle.CLOUD, spawn, 1, 0,0,0,0); - } - } - } - } - - public void Fire(Entity player, float delay, Integer amount) { - if (amount == null || amount == 0) - amount = this.shotAmount; - this.shotAmount = amount; - if (System.currentTimeMillis() < this.NextShotTime) { - return; - } - if (this.AmmoHolder.LoadedFuel <= 0) - this.AmmoHolder.LoadedFuel = 3; - float loadedFuel = this.AmmoHolder.LoadedFuel; - ItemStack LoadedProjectile = this.AmmoHolder.MaterialName; + public Location GetFireLocation(LivingEntity living) { + Location loc = living.getEyeLocation(); + Vector direction = living.getLocation().getDirection().multiply(XOffset); + loc.add(direction); + if (this.YOffset > 0) { + loc.setY(loc.getY() + this.YOffset); + } else { + loc.setY(loc.getY() - this.YOffset); + } + loc.setPitch(loc.getPitch() + this.PitchOffset); + return loc; + } + + public void ShowFireLocation(Entity player) { + LivingEntity living = (LivingEntity) this.Entity; + if (player instanceof Player) { + if (living != null) { + Location origin = this.GetFireLocation(living); + Vector direction = origin.getDirection(); + direction.multiply(5 /* the range */); + Location destination = origin.clone().add(direction); + + direction.normalize(); + for (int i = 0; i < 3 /* range */; i += 1) { + Location spawn = origin.add(direction); + ((Player) player).spawnParticle(Particle.CLOUD, spawn, 1, 0, 0, 0, 0); + } + } + } + } + + public void Fire(Entity player, float delay, Integer amount) { + if (amount == null || amount == 0) + amount = this.shotAmount; + this.shotAmount = amount; + if (System.currentTimeMillis() < this.NextShotTime) { + return; + } + if (this.AmmoHolder.LoadedFuel <= 0) + this.AmmoHolder.LoadedFuel = 3; + float loadedFuel = this.AmmoHolder.LoadedFuel; + ItemStack LoadedProjectile = this.AmmoHolder.MaterialName; - LivingEntity living = (LivingEntity) Entity; - if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { - return; - } - - if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) { - if (player instanceof Player) { - ((Player)player).sendMessage("§eCannot fire yet!"); - } - return; - } - this.AmmoHolder.LoadedFuel = 0; - this.AmmoHolder.LoadedProjectile = 0; - this.AmmoHolder.MaterialName = new ItemStack(Material.AIR, 1); + LivingEntity living = (LivingEntity) Entity; + if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { + return; + } - this.WorldName = Entity.getWorld().getName(); - this.NextShotTime = System.currentTimeMillis() + 1000; - for (int i = 0; i <= this.shotAmount /* range */; i+= 1) { - if (living == null || living.isDead()) { - return; - } - if (this.CycleThroughModelsBeforeFiring) { + if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) { + if (player instanceof Player) { + ((Player) player).sendMessage("§eCannot fire yet!"); + } + return; + } + this.AmmoHolder.LoadedFuel = 0; + this.AmmoHolder.LoadedProjectile = 0; + this.AmmoHolder.MaterialName = new ItemStack(Material.AIR, 1); - this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> { - if (living == null || living.isDead()) { - Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); - return; - } + this.WorldName = Entity.getWorld().getName(); + this.NextShotTime = System.currentTimeMillis() + 1000; + for (int i = 0; i <= this.shotAmount /* range */; i += 1) { + if (living == null || living.isDead()) { + return; + } + if (this.CycleThroughModelsBeforeFiring) { - if (this.HasFired) { - Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); - this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> { - if (living == null || living.isDead()) { - Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); - return; - } - // player.sendMessage("§etask"); - if (this.HasReloaded) { - Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); - this.HasReloaded = false; - this.HasFired = false; - this.NextModelNumber = 0; - SiegeEngines.UpdateEntityIdModel(this.Entity, this.ReadyModelNumber, this.WorldName); - this.TaskNumber = 0; - } - else { - //firing stages - if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) { - int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1); - // player.sendMessage("§e" + modelData); - SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); - this.NextModelNumber -= 1; + this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> { + if (living == null || living.isDead()) { + Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); + return; + } - }else { - // plugin.getLogger().log(Level.INFO, "its reloaded"); - this.HasReloaded = true; - } - } - }, 0, this.MillisecondsBetweenReloadingStages); + if (this.HasFired) { + Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); + this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> { + if (living == null || living.isDead()) { + Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); + return; + } + // player.sendMessage("§etask"); + if (this.HasReloaded) { + Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); + this.HasReloaded = false; + this.HasFired = false; + this.NextModelNumber = 0; + SiegeEngines.UpdateEntityIdModel(this.Entity, this.ReadyModelNumber, this.WorldName); + this.TaskNumber = 0; + } else { + //firing stages + if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) { + int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1); + // player.sendMessage("§e" + modelData); + SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); + this.NextModelNumber -= 1; - } - else { - //firing stages - if (this.NextModelNumber < this.FiringModelNumbers.size()) { + } else { + // plugin.getLogger().log(Level.INFO, "its reloaded"); + this.HasReloaded = true; + } + } + }, 0, this.MillisecondsBetweenReloadingStages); - int modelData = this.FiringModelNumbers.get(this.NextModelNumber); - // player.sendMessage("§e" + modelData); - SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); - if (modelData == this.ModelNumberToFireAt) { - // player.sendMessage("§efiring" + modelData); - Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); - } - this.NextModelNumber += 1; + } else { + //firing stages + if (this.NextModelNumber < this.FiringModelNumbers.size()) { - }else { - this.HasFired = true; + int modelData = this.FiringModelNumbers.get(this.NextModelNumber); + // player.sendMessage("§e" + modelData); + SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); + if (modelData == this.ModelNumberToFireAt) { + // player.sendMessage("§efiring" + modelData); + Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); + } + this.NextModelNumber += 1; - } - } - }, 0, this.MillisecondsBetweenFiringStages); - } else { - this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { - //player.sendMessage("§etask"); - if (living == null || living.isDead()) { - Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); - return; - } + } else { + this.HasFired = true; - Location loc = living.getEyeLocation(); - Vector direction = Entity.getLocation().getDirection().multiply(XOffset); + } + } + }, 0, this.MillisecondsBetweenFiringStages); + } else { + this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { + //player.sendMessage("§etask"); + if (living == null || living.isDead()) { + Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); + return; + } - loc.add(direction); + Location loc = living.getEyeLocation(); + Vector direction = Entity.getLocation().getDirection().multiply(XOffset); - this.NextModelNumber = 0; + loc.add(direction); - Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); - }, (long) delay); + this.NextModelNumber = 0; - } - } - } + Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); + }, (long) delay); + + } + } + } } diff --git a/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java b/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java index 2a8b1aa..262e50d 100644 --- a/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java +++ b/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java @@ -48,276 +48,276 @@ import com.github.alathra.siegeengines.projectile.GunnersProjectile; //import GunnersProjectiles.PotionProjectile; public class SiegeEngines extends JavaPlugin { - public static Plugin plugin; - public static MetadataValueAdapter metadata; - public static Random random = new Random(); - private static String Path; + public static Plugin plugin; + public static MetadataValueAdapter metadata; + public static Random random = new Random(); + private static String Path; - //public static Towny towny; - - @SuppressWarnings("deprecation") - @Override - public void onDisable() { - for (GunnerEquipment equip : equipment.values()) { - if (equip.Entity != null) { - ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); - ItemMeta meta = item.getItemMeta(); - equip.AmmoHolder = new EquipmentMagazine(); - - meta.setCustomModelData(equip.ReadyModelNumber); - meta.setDisplayName("§e" + equip.EquipmentName +" Item"); - List Lore = new ArrayList(); - Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand."); - meta.setLore(Lore); - item.setItemMeta(meta); + //public static Towny towny; - ((LivingEntity) equip.Entity).getEquipment().setHelmet(item); - } - } - } - - @SuppressWarnings("deprecation") - @Override - public void onEnable() { - plugin = this; - Path = this.getDataFolder().getAbsolutePath(); - this.getCommand("SiegeEngines").setExecutor(new GunnersCommand()); - getServer().getPluginManager().registerEvents(new RotationHandler(), this); - getServer().getPluginManager().registerEvents(new ClickHandler(), this); - //StorageManager.setup(Path, plugin); - equipment.clear(); - TrackedStands.clear(); - DefinedEquipment.clear(); - //AddDefaults(); - //HashMap projObj = new HashMap<>(); - //GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj); - for (GunnerEquipment i : DefinedEquipment.values()) { - System.out.println("§eEnabled Weapon : "+i.EquipmentName); - System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : "+i.FuelMaterial); - for (ItemStack proj : i.Projectiles.keySet()) { - System.out.println("§eWeapon Projectile ItemStacks : "+proj); - } - } - } - public static FixedMetadataValue addMetaDataValue(Object value) { - return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"),value); - } + @SuppressWarnings("deprecation") + @Override + public void onDisable() { + for (GunnerEquipment equip : equipment.values()) { + if (equip.Entity != null) { + ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); + ItemMeta meta = item.getItemMeta(); + equip.AmmoHolder = new EquipmentMagazine(); - public class GunnersCommand implements CommandExecutor { - @Override - @EventHandler - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - Player player = null; - if (sender instanceof Player) { - player = (Player) sender; - } - if (args != null && args.length > 0) { + meta.setCustomModelData(equip.ReadyModelNumber); + meta.setDisplayName("§e" + equip.EquipmentName + " Item"); + List Lore = new ArrayList(); + Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand."); + meta.setLore(Lore); + item.setItemMeta(meta); - switch (args[0].toLowerCase()) { - case "get": - if (player == null) { - sender.sendMessage("§eonly a player can use this command."); - return true; - } - if (!sender.hasPermission("SiegeEngines.get")) { - sender.sendMessage("§eNo perms to SiegeEngines.get"); - return true; - } - for (GunnerEquipment i : DefinedEquipment.values()) { - ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); - ItemMeta meta = item.getItemMeta(); - meta.setCustomModelData(i.ReadyModelNumber); - meta.setDisplayName("§e" + i.EquipmentName +" Item"); - List Lore = new ArrayList(); - Lore.add("§ePlace as a block to spawn a " + i.EquipmentName); - Lore.add("§eor put on an Armor Stand."); - Lore.add("§eRight click to toggle visibility of stand."); - meta.setLore(Lore); - item.setItemMeta(meta); - player.getInventory().addItem(item); - } - break; - case "reload": - if (!sender.hasPermission("SiegeEngines.reload")) { - sender.sendMessage("§eNo perms to SiegeEngines.reload"); - return true; - } - equipment.clear(); - TrackedStands.clear(); - DefinedEquipment.clear(); - AddDefaults(); - HashMap projObj = new HashMap<>(); - GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj); - for (GunnerEquipment i : DefinedEquipment.values()) { - sender.sendMessage("§eEnabled Weapon : "+i.EquipmentName); - sender.sendMessage("§eWeapon Propellant/\"Fuel\" ItemStacks : "+i.FuelMaterial); - for (ItemStack proj : i.Projectiles.keySet()) { - sender.sendMessage("§eWeapon Projectile ItemStacks : "+proj); - } - } - sender.sendMessage("§eGunners Core configs reloaded"); - break; - } + ((LivingEntity) equip.Entity).getEquipment().setHelmet(item); + } + } + } - } - else { - sender.sendMessage("§eIncorrect usage, /SiegeEngines get, /SiegeEngines reload"); - } - return true; - } - } + @SuppressWarnings("deprecation") + @Override + public void onEnable() { + plugin = this; + Path = this.getDataFolder().getAbsolutePath(); + this.getCommand("SiegeEngines").setExecutor(new GunnersCommand()); + getServer().getPluginManager().registerEvents(new RotationHandler(), this); + getServer().getPluginManager().registerEvents(new ClickHandler(), this); + //StorageManager.setup(Path, plugin); + equipment.clear(); + TrackedStands.clear(); + DefinedEquipment.clear(); + //AddDefaults(); + //HashMap projObj = new HashMap<>(); + //GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj); + for (GunnerEquipment i : DefinedEquipment.values()) { + System.out.println("§eEnabled Weapon : " + i.EquipmentName); + System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.FuelMaterial); + for (ItemStack proj : i.Projectiles.keySet()) { + System.out.println("§eWeapon Projectile ItemStacks : " + proj); + } + } + } - public static GunnerEquipment CreateClone(Integer ModelId) { - try { - return DefinedEquipment.get(ModelId).clone(); - } catch (CloneNotSupportedException e) { - // TODO Auto-generated catch block + public static FixedMetadataValue addMetaDataValue(Object value) { + return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value); + } - } - return null; - } + public class GunnersCommand implements CommandExecutor { + @Override + @EventHandler + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player player = null; + if (sender instanceof Player) { + player = (Player) sender; + } + if (args != null && args.length > 0) { - public static HashMap DefinedEquipment = new HashMap(); + switch (args[0].toLowerCase()) { + case "get": + if (player == null) { + sender.sendMessage("§eonly a player can use this command."); + return true; + } + if (!sender.hasPermission("SiegeEngines.get")) { + sender.sendMessage("§eNo perms to SiegeEngines.get"); + return true; + } + for (GunnerEquipment i : DefinedEquipment.values()) { + ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); + ItemMeta meta = item.getItemMeta(); + meta.setCustomModelData(i.ReadyModelNumber); + meta.setDisplayName("§e" + i.EquipmentName + " Item"); + List Lore = new ArrayList(); + Lore.add("§ePlace as a block to spawn a " + i.EquipmentName); + Lore.add("§eor put on an Armor Stand."); + Lore.add("§eRight click to toggle visibility of stand."); + meta.setLore(Lore); + item.setItemMeta(meta); + player.getInventory().addItem(item); + } + break; + case "reload": + if (!sender.hasPermission("SiegeEngines.reload")) { + sender.sendMessage("§eNo perms to SiegeEngines.reload"); + return true; + } + equipment.clear(); + TrackedStands.clear(); + DefinedEquipment.clear(); + AddDefaults(); + HashMap projObj = new HashMap<>(); + GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj); + for (GunnerEquipment i : DefinedEquipment.values()) { + sender.sendMessage("§eEnabled Weapon : " + i.EquipmentName); + sender.sendMessage("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.FuelMaterial); + for (ItemStack proj : i.Projectiles.keySet()) { + sender.sendMessage("§eWeapon Projectile ItemStacks : " + proj); + } + } + sender.sendMessage("§eGunners Core configs reloaded"); + break; + } - public static HashMap> TrackedStands = new HashMap>(); + } else { + sender.sendMessage("§eIncorrect usage, /SiegeEngines get, /SiegeEngines reload"); + } + return true; + } + } - public static HashMap equipment = new HashMap(); + public static GunnerEquipment CreateClone(Integer ModelId) { + try { + return DefinedEquipment.get(ModelId).clone(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block - public static String convertTime(long time){ + } + return null; + } - long days = TimeUnit.MILLISECONDS.toDays(time); - time -= TimeUnit.DAYS.toMillis(days); + public static HashMap DefinedEquipment = new HashMap(); - long hours = TimeUnit.MILLISECONDS.toHours(time); - time -= TimeUnit.HOURS.toMillis(hours); + public static HashMap> TrackedStands = new HashMap>(); - long minutes = TimeUnit.MILLISECONDS.toMinutes(time); - time -= TimeUnit.MINUTES.toMillis(minutes); + public static HashMap equipment = new HashMap(); - long seconds = TimeUnit.MILLISECONDS.toSeconds(time); - String timeLeftFormatted = String.format("§e" + minutes + " Minutes " +seconds +" Seconds§f"); + public static String convertTime(long time) { - return timeLeftFormatted; - } - - public static GunnerEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap projObj) { - GunnerEquipment equip = new GunnerEquipment(); - if (customModelId == null || customModelId == 0) - customModelId = 150; - if (name == null) - name = "Light Turret"; - if (XOffset == null) - XOffset = 0; - if (YOffset == null) - YOffset = 0; - if (fuelMax == null) - fuelMax = 0; - if (fuelVelocityMod == null) - fuelVelocityMod = 0.95f; - equip.EquipmentName = name; - equip.XOffset = XOffset; - equip.YOffset = YOffset; - equip.RotateStandHead = true; - equip.RotateSideways = true; - equip.PlacementOffsetY = -1.125f; - equip.ReadyModelNumber = customModelId; - equip.ModelNumberToFireAt = customModelId; - equip.FiringModelNumbers = new ArrayList(); - equip.VelocityPerFuel = fuelVelocityMod; - equip.FuelMaterial = new ItemStack(Material.GUNPOWDER); - equip.CycleThroughModelsBeforeFiring = false; - equip.AllowInvisibleStand = false; - equip.MaxFuel = fuelMax; - equip.shotAmount = 1; - equip.AmmoHolder.LoadedFuel = fuelMax; - EntityProjectile defaultProj = new EntityProjectile(); - defaultProj.EntityCount = 2; - defaultProj.EntityTyp = EntityType.SHULKER_BULLET; - defaultProj.ParticleType = Particle.WHITE_ASH; - defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; - if (projObj.keySet().isEmpty() || projObj.isEmpty()) - projObj.put(new ItemStack(Material.GUNPOWDER),defaultProj); - for (ItemStack mat : projObj.keySet()) { - equip.Projectiles.put(mat,projObj.get(mat)); - } - DefinedEquipment.put(equip.ReadyModelNumber,equip); - return equip; - } + long days = TimeUnit.MILLISECONDS.toDays(time); + time -= TimeUnit.DAYS.toMillis(days); - public static void AddDefaults() { - GunnerEquipment equip = new GunnerEquipment(); - equip.EquipmentName = "Trebuchet"; - equip.XOffset = 5; - equip.YOffset = 5; - equip.VelocityPerFuel = 0.3f; - ExplosiveProjectile proj = new ExplosiveProjectile(); - proj.ExplodePower = 2; - equip.shotAmount = 1; - equip.RotateStandHead = false; - equip.RotateSideways = true; - equip.FuelMaterial = new ItemStack(Material.STRING); - equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); - equip.ReadyModelNumber = 122; - equip.ModelNumberToFireAt = 135; - equip.MillisecondsBetweenFiringStages = 2; - equip.MillisecondsBetweenReloadingStages = 10; - equip.FiringModelNumbers = new ArrayList<>(Arrays.asList( - 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139 - )); - equip.CycleThroughModelsBeforeFiring = true; - DefinedEquipment.put(equip.ReadyModelNumber, equip); - - equip = new GunnerEquipment(); - equip.EquipmentName = "Naval Cannon"; - equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); - equip.PlacementOffsetY = -1; - equip.shotAmount = 1; - equip.ReadyModelNumber = 142; - equip.ModelNumberToFireAt = 142; - equip.FiringModelNumbers = new ArrayList(); - equip.RotateStandHead = true; - equip.RotateSideways = false; - proj = new ExplosiveProjectile(); - proj.ExplodePower = 1; - proj.ProjectilesCount = 3; - proj.DelayedFire = true; - proj.Inaccuracy = 0.75f; - equip.Projectiles.put(new ItemStack(Material.TNT), proj); - proj = new ExplosiveProjectile(); - proj.ExplodePower = 4; - proj.ProjectilesCount = 1; - equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj); + long hours = TimeUnit.MILLISECONDS.toHours(time); + time -= TimeUnit.HOURS.toMillis(hours); - EntityProjectile fireProj = new EntityProjectile(); - fireProj.EntityCount = 2; - fireProj.EntityTyp = EntityType.SMALL_FIREBALL; - fireProj.ParticleType = Particle.WHITE_ASH; - fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; - equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj); - DefinedEquipment.put(equip.ReadyModelNumber, equip); - equip = new GunnerEquipment(); - equip.EquipmentName = "Siege Cannon"; - proj.ExplodePower = 2; - equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); - equip.shotAmount = 1; - equip.PlacementOffsetY = -1; - equip.ReadyModelNumber = 141; - equip.ModelNumberToFireAt = 141; - equip.FiringModelNumbers = new ArrayList(); - equip.RotateStandHead = true; - equip.RotateSideways = true; - proj = new ExplosiveProjectile(); - proj.ExplodePower = 1; - proj.ProjectilesCount = 3; - proj.DelayedFire = true; - proj.Inaccuracy = 0.5f; - equip.Projectiles.put(new ItemStack(Material.TNT), proj); - proj = new ExplosiveProjectile(); - proj.ExplodePower = 4; - proj.ProjectilesCount = 1; - equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj); - equip.Projectiles.put(new ItemStack(Material.GRAVEL), new EntityProjectile()); - DefinedEquipment.put(equip.ReadyModelNumber, equip); + long minutes = TimeUnit.MILLISECONDS.toMinutes(time); + time -= TimeUnit.MINUTES.toMillis(minutes); + + long seconds = TimeUnit.MILLISECONDS.toSeconds(time); + String timeLeftFormatted = String.format("§e" + minutes + " Minutes " + seconds + " Seconds§f"); + + return timeLeftFormatted; + } + + public static GunnerEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap projObj) { + GunnerEquipment equip = new GunnerEquipment(); + if (customModelId == null || customModelId == 0) + customModelId = 150; + if (name == null) + name = "Light Turret"; + if (XOffset == null) + XOffset = 0; + if (YOffset == null) + YOffset = 0; + if (fuelMax == null) + fuelMax = 0; + if (fuelVelocityMod == null) + fuelVelocityMod = 0.95f; + equip.EquipmentName = name; + equip.XOffset = XOffset; + equip.YOffset = YOffset; + equip.RotateStandHead = true; + equip.RotateSideways = true; + equip.PlacementOffsetY = -1.125f; + equip.ReadyModelNumber = customModelId; + equip.ModelNumberToFireAt = customModelId; + equip.FiringModelNumbers = new ArrayList(); + equip.VelocityPerFuel = fuelVelocityMod; + equip.FuelMaterial = new ItemStack(Material.GUNPOWDER); + equip.CycleThroughModelsBeforeFiring = false; + equip.AllowInvisibleStand = false; + equip.MaxFuel = fuelMax; + equip.shotAmount = 1; + equip.AmmoHolder.LoadedFuel = fuelMax; + EntityProjectile defaultProj = new EntityProjectile(); + defaultProj.EntityCount = 2; + defaultProj.EntityTyp = EntityType.SHULKER_BULLET; + defaultProj.ParticleType = Particle.WHITE_ASH; + defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; + if (projObj.keySet().isEmpty() || projObj.isEmpty()) + projObj.put(new ItemStack(Material.GUNPOWDER), defaultProj); + for (ItemStack mat : projObj.keySet()) { + equip.Projectiles.put(mat, projObj.get(mat)); + } + DefinedEquipment.put(equip.ReadyModelNumber, equip); + return equip; + } + + public static void AddDefaults() { + GunnerEquipment equip = new GunnerEquipment(); + equip.EquipmentName = "Trebuchet"; + equip.XOffset = 5; + equip.YOffset = 5; + equip.VelocityPerFuel = 0.3f; + ExplosiveProjectile proj = new ExplosiveProjectile(); + proj.ExplodePower = 2; + equip.shotAmount = 1; + equip.RotateStandHead = false; + equip.RotateSideways = true; + equip.FuelMaterial = new ItemStack(Material.STRING); + equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); + equip.ReadyModelNumber = 122; + equip.ModelNumberToFireAt = 135; + equip.MillisecondsBetweenFiringStages = 2; + equip.MillisecondsBetweenReloadingStages = 10; + equip.FiringModelNumbers = new ArrayList<>(Arrays.asList( + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139 + )); + equip.CycleThroughModelsBeforeFiring = true; + DefinedEquipment.put(equip.ReadyModelNumber, equip); + + equip = new GunnerEquipment(); + equip.EquipmentName = "Naval Cannon"; + equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); + equip.PlacementOffsetY = -1; + equip.shotAmount = 1; + equip.ReadyModelNumber = 142; + equip.ModelNumberToFireAt = 142; + equip.FiringModelNumbers = new ArrayList(); + equip.RotateStandHead = true; + equip.RotateSideways = false; + proj = new ExplosiveProjectile(); + proj.ExplodePower = 1; + proj.ProjectilesCount = 3; + proj.DelayedFire = true; + proj.Inaccuracy = 0.75f; + equip.Projectiles.put(new ItemStack(Material.TNT), proj); + proj = new ExplosiveProjectile(); + proj.ExplodePower = 4; + proj.ProjectilesCount = 1; + equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj); + + EntityProjectile fireProj = new EntityProjectile(); + fireProj.EntityCount = 2; + fireProj.EntityTyp = EntityType.SMALL_FIREBALL; + fireProj.ParticleType = Particle.WHITE_ASH; + fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; + equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj); + DefinedEquipment.put(equip.ReadyModelNumber, equip); + equip = new GunnerEquipment(); + equip.EquipmentName = "Siege Cannon"; + proj.ExplodePower = 2; + equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj); + equip.shotAmount = 1; + equip.PlacementOffsetY = -1; + equip.ReadyModelNumber = 141; + equip.ModelNumberToFireAt = 141; + equip.FiringModelNumbers = new ArrayList(); + equip.RotateStandHead = true; + equip.RotateSideways = true; + proj = new ExplosiveProjectile(); + proj.ExplodePower = 1; + proj.ProjectilesCount = 3; + proj.DelayedFire = true; + proj.Inaccuracy = 0.5f; + equip.Projectiles.put(new ItemStack(Material.TNT), proj); + proj = new ExplosiveProjectile(); + proj.ExplodePower = 4; + proj.ProjectilesCount = 1; + equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj); + equip.Projectiles.put(new ItemStack(Material.GRAVEL), new EntityProjectile()); + DefinedEquipment.put(equip.ReadyModelNumber, equip); // EntityProjectile pig = new EntityProjectile(); // pig.EntityCount = 100; // pig.DelayedFire = true; @@ -328,121 +328,119 @@ public class SiegeEngines extends JavaPlugin { // equip.Projectiles.put(Material.PORKCHOP, pig); // equip.Projectiles.put(Material.BONE, new PotionProjectile()); - } + } - public static Boolean CreateCannon(Entity player, int CustomModelData, Location l) { - //l.setY(l.getY() - 1); - l.add(0.5, 0, 0.5); - NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); - GunnerEquipment equip = CreateClone(CustomModelData); - if (equip == null || !equip.Enabled) { - return false; - } - l.setY(l.getY() + 1); - int maxNearby = 0; + public static Boolean CreateCannon(Entity player, int CustomModelData, Location l) { + //l.setY(l.getY() - 1); + l.add(0.5, 0, 0.5); + NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); + GunnerEquipment equip = CreateClone(CustomModelData); + if (equip == null || !equip.Enabled) { + return false; + } + l.setY(l.getY() + 1); + int maxNearby = 0; - l.setDirection(player.getFacing().getDirection()); - ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); - ItemMeta meta = item.getItemMeta(); - String id = ""; - equip.AmmoHolder = new EquipmentMagazine(); - if (equip.HaseBaseStand) { - - Location l2 = l; - l2.setY(l.getY() + equip.BaseStandOffset); - Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); - - LivingEntity ent = (LivingEntity) entity3; - ArmorStand stand = (ArmorStand) ent; - id = entity3.getUniqueId().toString(); - meta.setCustomModelData(equip.BaseStandModelNumber); - stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING); - stand.setBasePlate(false); - // stand.setSmall(true); - item.setItemMeta(meta); - stand.setInvisible(equip.AllowInvisibleStand); - ent.getEquipment().setHelmet(item); - stand.setGravity(false); - stand.setMarker(true); - } - l.setY(l.getY() + equip.PlacementOffsetY); - Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); - if (id != "") { - entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id); - } - meta.setCustomModelData(equip.ReadyModelNumber); - meta.setDisplayName("§e" + equip.EquipmentName +" Item"); - List Lore = new ArrayList(); - Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand."); - meta.setLore(Lore); - item.setItemMeta(meta); + l.setDirection(player.getFacing().getDirection()); + ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); + ItemMeta meta = item.getItemMeta(); + String id = ""; + equip.AmmoHolder = new EquipmentMagazine(); + if (equip.HaseBaseStand) { - // entity3.addPassenger(entity2); - - LivingEntity ent = (LivingEntity) entity2; - ArmorStand stand = (ArmorStand) ent; - equip.Entity = entity2; - for (Entity le : l.getNearbyEntities(5, 5, 5)) { - if (maxNearby >= 4) { - ent.damage(100.0d,player); - return false; - } - if (le instanceof ArmorStand) - maxNearby++; - } - - equip.EntityId = entity2.getUniqueId(); - stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING); - stand.setInvisible(equip.AllowInvisibleStand); - stand.setBasePlate(false); - ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1)); - // stand.setSmall(true); - - stand.setGravity(false); - //stand.setSmall(true); - ent.getEquipment().setHelmet(item); - if (TrackedStands.containsKey(player.getUniqueId())) { - List entities = TrackedStands.get(player.getUniqueId()); - entities.add(entity2); - TrackedStands.put(player.getUniqueId(), entities); - } - else { - List newList = new ArrayList(); - newList.add(entity2); - TrackedStands.put(player.getUniqueId(), newList); - } - equipment.put(entity2.getUniqueId(), equip); - return true; - } + Location l2 = l; + l2.setY(l.getY() + equip.BaseStandOffset); + Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); - public static void UpdateEntityIdModel(Entity ent, int modelNumber, String WorldName) { - if (ent instanceof LivingEntity) - { - LivingEntity liv = (LivingEntity) ent; - ItemStack Helmet = liv.getEquipment().getHelmet(); - if (Helmet != null) { - ItemMeta meta = Helmet.getItemMeta(); - meta.setCustomModelData(modelNumber); - Helmet.setItemMeta(meta); - liv.getEquipment().setHelmet(Helmet); - // plugin.getLogger().log(Level.INFO, "Updating stand?"); - } - } - } + LivingEntity ent = (LivingEntity) entity3; + ArmorStand stand = (ArmorStand) ent; + id = entity3.getUniqueId().toString(); + meta.setCustomModelData(equip.BaseStandModelNumber); + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING); + stand.setBasePlate(false); + // stand.setSmall(true); + item.setItemMeta(meta); + stand.setInvisible(equip.AllowInvisibleStand); + ent.getEquipment().setHelmet(item); + stand.setGravity(false); + stand.setMarker(true); + } + l.setY(l.getY() + equip.PlacementOffsetY); + Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); + if (id != "") { + entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id); + } + meta.setCustomModelData(equip.ReadyModelNumber); + meta.setDisplayName("§e" + equip.EquipmentName + " Item"); + List Lore = new ArrayList(); + Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand."); + meta.setLore(Lore); + item.setItemMeta(meta); + + // entity3.addPassenger(entity2); + + LivingEntity ent = (LivingEntity) entity2; + ArmorStand stand = (ArmorStand) ent; + equip.Entity = entity2; + for (Entity le : l.getNearbyEntities(5, 5, 5)) { + if (maxNearby >= 4) { + ent.damage(100.0d, player); + return false; + } + if (le instanceof ArmorStand) + maxNearby++; + } + + equip.EntityId = entity2.getUniqueId(); + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING); + stand.setInvisible(equip.AllowInvisibleStand); + stand.setBasePlate(false); + ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1)); + // stand.setSmall(true); + + stand.setGravity(false); + //stand.setSmall(true); + ent.getEquipment().setHelmet(item); + if (TrackedStands.containsKey(player.getUniqueId())) { + List entities = TrackedStands.get(player.getUniqueId()); + entities.add(entity2); + TrackedStands.put(player.getUniqueId(), entities); + } else { + List newList = new ArrayList(); + newList.add(entity2); + TrackedStands.put(player.getUniqueId(), newList); + } + equipment.put(entity2.getUniqueId(), equip); + return true; + } + + public static void UpdateEntityIdModel(Entity ent, int modelNumber, String WorldName) { + if (ent instanceof LivingEntity) { + LivingEntity liv = (LivingEntity) ent; + ItemStack Helmet = liv.getEquipment().getHelmet(); + if (Helmet != null) { + ItemMeta meta = Helmet.getItemMeta(); + meta.setCustomModelData(modelNumber); + Helmet.setItemMeta(meta); + liv.getEquipment().setHelmet(Helmet); + // plugin.getLogger().log(Level.INFO, "Updating stand?"); + } + } + } } diff --git a/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java b/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java index a332536..231e939 100644 --- a/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java +++ b/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java @@ -54,14 +54,15 @@ import com.github.alathra.siegeengines.projectile.ExplosiveProjectile; public class ClickHandler implements Listener { - public float MinDelay = 5; + public float MinDelay = 5; - public static HashMap projectiles = new HashMap(); - @EventHandler - public void onExplode(EntityExplodeEvent e) { - for (Entity entity : e.getEntity().getNearbyEntities(e.getYield() + 1, e.getYield()+ 1, e.getYield()+ 1)) { - if(entity instanceof ArmorStand) { - ArmorStand stand = (ArmorStand) entity; + public static HashMap projectiles = new HashMap(); + + @EventHandler + public void onExplode(EntityExplodeEvent e) { + for (Entity entity : e.getEntity().getNearbyEntities(e.getYield() + 1, e.getYield() + 1, e.getYield() + 1)) { + if (entity instanceof ArmorStand) { + ArmorStand stand = (ArmorStand) entity; /*if (SiegeEngines.towny != null) { TownBlock block = TownyAPI.getInstance().getTownBlock(stand.getLocation()); if (block != null) { @@ -72,33 +73,33 @@ public class ClickHandler implements Listener { } } }*/ - stand.eject(); - stand.remove(); - } - } - } + stand.eject(); + stand.remove(); + } + } + } - @EventHandler - public void onHit(ProjectileHitEvent event) { - if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) { - ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId()); - Entity snowball = event.getEntity(); - Snowball ball = (Snowball) snowball; - Entity player = (Entity) ball.getShooter(); - if (player instanceof Player) { - player.sendMessage("§eDistance to impact: " + String.format("%.2f",player.getLocation().distance(ball.getLocation()))); - } - Location loc = snowball.getLocation(); - World world = event.getEntity().getWorld(); - // world.createExplosion(loc, proj.Radius, proj.DoFire); - Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT); + @EventHandler + public void onHit(ProjectileHitEvent event) { + if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) { + ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId()); + Entity snowball = event.getEntity(); + Snowball ball = (Snowball) snowball; + Entity player = (Entity) ball.getShooter(); + if (player instanceof Player) { + player.sendMessage("§eDistance to impact: " + String.format("%.2f", player.getLocation().distance(ball.getLocation()))); + } + Location loc = snowball.getLocation(); + World world = event.getEntity().getWorld(); + // world.createExplosion(loc, proj.Radius, proj.DoFire); + Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT); - projectiles.remove(event.getEntity().getUniqueId()); + projectiles.remove(event.getEntity().getUniqueId()); - if (proj.PlaceBlocks) { - TNTPrimed tntEnt = (TNTPrimed) tnt; - tntEnt.setYield(0); - tntEnt.setFuseTicks(0); + if (proj.PlaceBlocks) { + TNTPrimed tntEnt = (TNTPrimed) tnt; + tntEnt.setYield(0); + tntEnt.setFuseTicks(0); /*if (SiegeEngines.towny != null) { TownBlock block = TownyAPI.getInstance().getTownBlock(loc); if (block != null) { @@ -109,629 +110,623 @@ public class ClickHandler implements Listener { } } }*/ - if (event.getHitBlock() != null) { - List Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower); - for (int i = 0; i < proj.BlocksToPlaceAmount; i++) { - Block replace = getRandomElement(Blocks); - replace.setType(proj.BlockToPlace); - } - } - } - else { - TNTPrimed tntEnt = (TNTPrimed) tnt; - tntEnt.setYield(proj.ExplodePower); - tntEnt.setFuseTicks(0); - } - } - } + if (event.getHitBlock() != null) { + List Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower); + for (int i = 0; i < proj.BlocksToPlaceAmount; i++) { + Block replace = getRandomElement(Blocks); + replace.setType(proj.BlockToPlace); + } + } + } else { + TNTPrimed tntEnt = (TNTPrimed) tnt; + tntEnt.setYield(proj.ExplodePower); + tntEnt.setFuseTicks(0); + } + } + } - public ArrayList sphere(final Location center, final int radius) { - ArrayList sphere = new ArrayList(); - for (int Y = -radius; Y < radius; Y++) { - for (int X = -radius; X < radius; X++) { - for (int Z = -radius; Z < radius; Z++) { - if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) { - final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ()); - if (block.getType() == Material.AIR) { - sphere.add(block); - } - } - } - } - } - return sphere; - } + public ArrayList sphere(final Location center, final int radius) { + ArrayList sphere = new ArrayList(); + for (int Y = -radius; Y < radius; Y++) { + for (int X = -radius; X < radius; X++) { + for (int Z = -radius; Z < radius; Z++) { + if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) { + final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ()); + if (block.getType() == Material.AIR) { + sphere.add(block); + } + } + } + } + } + return sphere; + } - public Block getRandomElement(List list) - { - Random rand = new Random(); - return list.get(rand.nextInt(list.size())); - } + public Block getRandomElement(List list) { + Random rand = new Random(); + return list.get(rand.nextInt(list.size())); + } - @EventHandler(priority = EventPriority.HIGH) - public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) { - Player thePlayer = event.getPlayer(); - if (event.isCancelled()) - return; - if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) { - ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); - if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) { - int customModel = item.getItemMeta().getCustomModelData(); - Boolean created = SiegeEngines.CreateCannon(thePlayer, customModel, event.getBlockAgainst().getLocation()); - if (created) { - item.setAmount(item.getAmount() - 1); - thePlayer.getInventory().setItemInMainHand(item); - thePlayer.sendMessage("§eGunner Equipment spawned!"); - } else { - thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?"); - } - event.setCancelled(true); - } - } - } + @EventHandler(priority = EventPriority.HIGH) + public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) { + Player thePlayer = event.getPlayer(); + if (event.isCancelled()) + return; + if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) { + ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); + if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) { + int customModel = item.getItemMeta().getCustomModelData(); + Boolean created = SiegeEngines.CreateCannon(thePlayer, customModel, event.getBlockAgainst().getLocation()); + if (created) { + item.setAmount(item.getAmount() - 1); + thePlayer.getInventory().setItemInMainHand(item); + thePlayer.sendMessage("§eGunner Equipment spawned!"); + } else { + thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?"); + } + event.setCancelled(true); + } + } + } - public void Shoot(Entity player, long delay) { - float actualDelay = delay; - Boolean FirstShot = true; - int counter = 0; - if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null) { - for (Entity ent : player.getNearbyEntities(5, 5, 5)) { - if(ent instanceof ArmorStand) { - TakeControl(player,ent); - } - } - } - if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null) - return; - List entities = new ArrayList<>(SiegeEngines.TrackedStands.get(player.getUniqueId())); - for (Entity ent : entities){ - if (ent == null || ent.isDead()) { - SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); - continue; - } - if (((LivingEntity) ent).getEquipment().getHelmet().getType() != Material.CARVED_PUMPKIN) { - SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); - continue; - } - double distance = player.getLocation().distance(ent.getLocation()); - if (distance >= 127) { - continue; - } - GunnerEquipment siege = SiegeEngines.equipment.get(ent.getUniqueId()); - if (counter > 4) - return; - if (ent == null || ent.isDead()) { - SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); - continue; - } - if (siege.isLoaded()) { - if (player instanceof Player) { - siege.Fire(player, actualDelay,1); - actualDelay += delay; - } else { - siege.Fire(player,15,1); - } - counter++; - } - else { - if (player instanceof Player) {} - //player.sendMessage("§eAmmunition Not Loaded"); - } - // player.sendMessage(String.format("§e" +actualDelay)); + public void Shoot(Entity player, long delay) { + float actualDelay = delay; + Boolean FirstShot = true; + int counter = 0; + if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null) { + for (Entity ent : player.getNearbyEntities(5, 5, 5)) { + if (ent instanceof ArmorStand) { + TakeControl(player, ent); + } + } + } + if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null) + return; + List entities = new ArrayList<>(SiegeEngines.TrackedStands.get(player.getUniqueId())); + for (Entity ent : entities) { + if (ent == null || ent.isDead()) { + SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); + continue; + } + if (((LivingEntity) ent).getEquipment().getHelmet().getType() != Material.CARVED_PUMPKIN) { + SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); + continue; + } + double distance = player.getLocation().distance(ent.getLocation()); + if (distance >= 127) { + continue; + } + GunnerEquipment siege = SiegeEngines.equipment.get(ent.getUniqueId()); + if (counter > 4) + return; + if (ent == null || ent.isDead()) { + SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent); + continue; + } + if (siege.isLoaded()) { + if (player instanceof Player) { + siege.Fire(player, actualDelay, 1); + actualDelay += delay; + } else { + siege.Fire(player, 15, 1); + } + counter++; + } else { + if (player instanceof Player) { + } + //player.sendMessage("§eAmmunition Not Loaded"); + } + // player.sendMessage(String.format("§e" +actualDelay)); - } - } - public static ItemStack[] updateContents(Inventory inv, ItemStack m, int toRemove) { - ItemStack[] contents = inv.getStorageContents(); - for(int i = 0; i < contents.length; i++) { - if(contents[i] == null) continue; - if(contents[i].isSimilar(m)) { - System.out.println(m.toString()); - int amountInInv = contents[i].getAmount(); - if(toRemove >= amountInInv) { - contents[i].setType(Material.AIR); - toRemove -= amountInInv; - } else { - contents[i].setAmount(amountInInv-toRemove); - toRemove = 0; - break; - } - } - if(toRemove <= 0) break; - } - return contents; - } + } + } - @EventHandler - public void interact(PlayerInteractEvent event) { - Player player = event.getPlayer(); + public static ItemStack[] updateContents(Inventory inv, ItemStack m, int toRemove) { + ItemStack[] contents = inv.getStorageContents(); + for (int i = 0; i < contents.length; i++) { + if (contents[i] == null) continue; + if (contents[i].isSimilar(m)) { + System.out.println(m.toString()); + int amountInInv = contents[i].getAmount(); + if (toRemove >= amountInInv) { + contents[i].setType(Material.AIR); + toRemove -= amountInInv; + } else { + contents[i].setAmount(amountInInv - toRemove); + toRemove = 0; + break; + } + } + if (toRemove <= 0) break; + } + return contents; + } - ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand(); - if (ItemInHand == null) { - return; - } + @EventHandler + public void interact(PlayerInteractEvent event) { + Player player = event.getPlayer(); - // if (ItemInHand.getType() == Material.PAPER) { - // ItemMeta meta = ItemInHand.getItemMeta(); - // if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) { - // SiegeEngines.CreateCannon(player); - // ItemInHand.setAmount(ItemInHand.getAmount() - 1); - // return; - // } - // } + ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand(); + if (ItemInHand == null) { + return; + } + + // if (ItemInHand.getType() == Material.PAPER) { + // ItemMeta meta = ItemInHand.getItemMeta(); + // if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) { + // SiegeEngines.CreateCannon(player); + // ItemInHand.setAmount(ItemInHand.getAmount() - 1); + // return; + // } + // } - if (event.getAction() == Action.RIGHT_CLICK_AIR) { - if (ItemInHand.getType() != Material.COMPASS) { - return; - } - if (!player.isSneaking()) - Shoot((Entity)player, 7); - if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); - for (Entity entity : entities) { - boolean foundAmmo = false; - if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { - GunnerEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId()); - if (equip == null || !equip.Enabled) { - continue; - } - if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) { - Block inv = entity.getLocation().getBlock(); - Container state = ((Container)inv.getState()); - for (ItemStack stack : equip.Projectiles.keySet()) { - if (foundAmmo) - continue; - state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); - //state.update(true,true); - equip.AmmoHolder.LoadedProjectile = 1; - equip.AmmoHolder.MaterialName = stack; - foundAmmo = true; - } - //state.update(true,true); - } - if (foundAmmo) - continue; - if (entity.getLocation().getBlock().getRelative(0,-1,0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0,-1,0).getType() == Material.CHEST) { - Block inv = entity.getLocation().getBlock().getRelative(0,-1,0); - Container state = ((Container)inv.getState()); - for (ItemStack stack : equip.Projectiles.keySet()) { - if (foundAmmo) - continue; - state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); - //state.update(true,true); - equip.AmmoHolder.LoadedProjectile = 1; - equip.AmmoHolder.MaterialName = stack; - foundAmmo = true; - } - //state.update(true,true); - } - if (foundAmmo) - continue; - if (entity.getLocation().getBlock().getRelative(0,1,0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0,1,0).getType() == Material.CHEST) { - Block inv = entity.getLocation().getBlock().getRelative(0,1,0); - Container state = ((Container)inv.getState()); - for (ItemStack stack : equip.Projectiles.keySet()) { - if (foundAmmo) - continue; - state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); - //state.update(true,true); - equip.AmmoHolder.LoadedProjectile = 1; - equip.AmmoHolder.MaterialName = stack; - foundAmmo = true; - } - //state.update(true,true); - } - if (foundAmmo) - continue; - if (!player.isSneaking()) - return; - if (!foundAmmo) { - for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) { - for (ItemStack stack : equip.Projectiles.keySet()) { - if (foundAmmo) - continue; - if (stack.isSimilar(inventoryItem) && equip.AmmoHolder.LoadedProjectile == 0){ - equip.AmmoHolder.LoadedProjectile = 1; - equip.AmmoHolder.MaterialName = stack; - inventoryItem.setAmount(inventoryItem.getAmount() - 1); - foundAmmo = true; - } - } - } - } - } - } - player.sendMessage("§eReloading Ammunition"); - return; - } + if (event.getAction() == Action.RIGHT_CLICK_AIR) { + if (ItemInHand.getType() != Material.COMPASS) { + return; + } + if (!player.isSneaking()) + Shoot((Entity) player, 7); + if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); + for (Entity entity : entities) { + boolean foundAmmo = false; + if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { + GunnerEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId()); + if (equip == null || !equip.Enabled) { + continue; + } + if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) { + Block inv = entity.getLocation().getBlock(); + Container state = ((Container) inv.getState()); + for (ItemStack stack : equip.Projectiles.keySet()) { + if (foundAmmo) + continue; + state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); + //state.update(true,true); + equip.AmmoHolder.LoadedProjectile = 1; + equip.AmmoHolder.MaterialName = stack; + foundAmmo = true; + } + //state.update(true,true); + } + if (foundAmmo) + continue; + if (entity.getLocation().getBlock().getRelative(0, -1, 0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0, -1, 0).getType() == Material.CHEST) { + Block inv = entity.getLocation().getBlock().getRelative(0, -1, 0); + Container state = ((Container) inv.getState()); + for (ItemStack stack : equip.Projectiles.keySet()) { + if (foundAmmo) + continue; + state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); + //state.update(true,true); + equip.AmmoHolder.LoadedProjectile = 1; + equip.AmmoHolder.MaterialName = stack; + foundAmmo = true; + } + //state.update(true,true); + } + if (foundAmmo) + continue; + if (entity.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.CHEST) { + Block inv = entity.getLocation().getBlock().getRelative(0, 1, 0); + Container state = ((Container) inv.getState()); + for (ItemStack stack : equip.Projectiles.keySet()) { + if (foundAmmo) + continue; + state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1)); + //state.update(true,true); + equip.AmmoHolder.LoadedProjectile = 1; + equip.AmmoHolder.MaterialName = stack; + foundAmmo = true; + } + //state.update(true,true); + } + if (foundAmmo) + continue; + if (!player.isSneaking()) + return; + if (!foundAmmo) { + for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) { + for (ItemStack stack : equip.Projectiles.keySet()) { + if (foundAmmo) + continue; + if (stack.isSimilar(inventoryItem) && equip.AmmoHolder.LoadedProjectile == 0) { + equip.AmmoHolder.LoadedProjectile = 1; + equip.AmmoHolder.MaterialName = stack; + inventoryItem.setAmount(inventoryItem.getAmount() - 1); + foundAmmo = true; + } + } + } + } + } + } + player.sendMessage("§eReloading Ammunition"); + return; + } - } - } + } + } - @EventHandler(priority = EventPriority.NORMAL) - public void onSignChange(SignChangeEvent event){ - String topline = event.getLine(0); - if (topline == null) topline = ""; - Player player = event.getPlayer(); - String toplinetrimmed = topline.trim(); - if (toplinetrimmed.equals("[Cannon]")) { - SaveCannons(player, event.getBlock()); - } + @EventHandler(priority = EventPriority.NORMAL) + public void onSignChange(SignChangeEvent event) { + String topline = event.getLine(0); + if (topline == null) topline = ""; + Player player = event.getPlayer(); + String toplinetrimmed = topline.trim(); + if (toplinetrimmed.equals("[Cannon]")) { + SaveCannons(player, event.getBlock()); + } - } + } - @EventHandler - public void damage(EntityDamageByEntityEvent event){ - if (event.getEntity() instanceof ArmorStand) { - if (event.getDamager() instanceof Projectile) { - event.setDamage(0); - event.setCancelled(true); - } - } - } + @EventHandler + public void damage(EntityDamageByEntityEvent event) { + if (event.getEntity() instanceof ArmorStand) { + if (event.getDamager() instanceof Projectile) { + event.setDamage(0); + event.setCancelled(true); + } + } + } + public static void TakeControl(Entity player, Entity entity) { + LivingEntity living = (LivingEntity) entity; + if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); + if (entities.contains(entity)) { + return; + } + } - public static void TakeControl(Entity player, Entity entity) { - LivingEntity living = (LivingEntity) entity; - if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); - if (entities.contains(entity)) { - return; - } - } + if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) { + if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { + return; + } - if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) { - if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { - return; - } + ArmorStand stand = (ArmorStand) entity; + GunnerEquipment equip; + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); + stand.setBasePlate(false); - ArmorStand stand = (ArmorStand) entity; - GunnerEquipment equip; - stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); - stand.setBasePlate(false); + if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { + equip = SiegeEngines.equipment.get(entity.getUniqueId()); + if (equip == null || !equip.Enabled) { + return; + } + } else { + equip = SiegeEngines.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData()); + if (equip == null || !equip.Enabled) { + return; + } + equip.AmmoHolder = new EquipmentMagazine(); + equip.Entity = entity; + equip.EntityId = entity.getUniqueId(); + } + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); + stand.setBasePlate(false); + if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); + entities.add(entity); + SiegeEngines.TrackedStands.put(player.getUniqueId(), entities); + } else { + List newList = new ArrayList(); + newList.add(entity); + SiegeEngines.TrackedStands.put(player.getUniqueId(), newList); + } + SiegeEngines.equipment.put(entity.getUniqueId(), equip); + //player.sendMessage("§eNow controlling the equipment."); + } + } - if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { - equip = SiegeEngines.equipment.get(entity.getUniqueId()); - if (equip == null || !equip.Enabled) { - return; - } - } - else { - equip = SiegeEngines.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData()); - if (equip == null || !equip.Enabled) { - return; - } - equip.AmmoHolder = new EquipmentMagazine(); - equip.Entity = entity; - equip.EntityId = entity.getUniqueId(); - } - stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); - stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); - stand.setBasePlate(false); - if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - List entities = SiegeEngines.TrackedStands.get(player.getUniqueId()); - entities.add(entity); - SiegeEngines.TrackedStands.put(player.getUniqueId(), entities); - } - else { - List newList = new ArrayList(); - newList.add(entity); - SiegeEngines.TrackedStands.put(player.getUniqueId(), newList); - } - SiegeEngines.equipment.put(entity.getUniqueId(), equip); - //player.sendMessage("§eNow controlling the equipment."); - } - } + public void SaveCannons(Player player, Block block) { + List Ids = new ArrayList(); + if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + return; + } + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + Ids.add(ent.getUniqueId().toString()); + } + TileState state = ((TileState) block.getState()); + NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); - public void SaveCannons(Player player, Block block) { - List Ids = new ArrayList(); - if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - return; - } - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - Ids.add(ent.getUniqueId().toString()); - } - TileState state = ((TileState) block.getState()); - NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent.isDead()) { + continue; + } + DoAimUp(ent, 0, player); + } + } - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent.isDead()) { - continue; - } - DoAimUp(ent, 0, player); - } - } + public void DoAimUp(Entity ent, float amount, Entity player) { + Location loc = ent.getLocation(); + ArmorStand stand = (ArmorStand) ent; + // player.sendMessage(String.format("" + loc.getPitch())); + if (loc.getPitch() == -85 || loc.getPitch() - amount < -85) { + return; + } + loc.setPitch((float) (loc.getPitch() - amount)); + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (equipment != null) { + if (player instanceof Player) + equipment.ShowFireLocation(player); + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0)); + } + ent.teleport(loc); + } + } - public void DoAimUp(Entity ent, float amount, Entity player) { - Location loc = ent.getLocation(); - ArmorStand stand = (ArmorStand) ent; - // player.sendMessage(String.format("" + loc.getPitch())); - if (loc.getPitch() == -85 || loc.getPitch() - amount < -85) { - return; - } - loc.setPitch((float) (loc.getPitch() - amount)); - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (equipment != null) { - if (player instanceof Player) - equipment.ShowFireLocation(player); - if (equipment.RotateStandHead) { - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); - } - ent.teleport(loc); - } - } + public void DoAimDown(Entity ent, float amount, Entity player) { + Location loc = ent.getLocation(); + ArmorStand stand = (ArmorStand) ent; + // player.sendMessage(String.format("" + loc.getPitch())); + if (loc.getPitch() == 85 || loc.getPitch() - amount < 65) { + return; + } + loc.setPitch((float) (loc.getPitch() - amount)); + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (equipment != null) { + if (player instanceof Player) + equipment.ShowFireLocation(player); + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0)); + } + ent.teleport(loc); + } + } - public void DoAimDown(Entity ent, float amount, Entity player) { - Location loc = ent.getLocation(); - ArmorStand stand = (ArmorStand) ent; - // player.sendMessage(String.format("" + loc.getPitch())); - if (loc.getPitch() == 85 || loc.getPitch() - amount < 65) { - return; - } - loc.setPitch((float) (loc.getPitch() - amount)); - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (equipment != null) { - if (player instanceof Player) - equipment.ShowFireLocation(player); - if (equipment.RotateStandHead) { - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); - } - ent.teleport(loc); - } - } + public void FirstShotDoAimDown(Entity ent, float amount, Entity player) { + Location loc = ent.getLocation(); + ArmorStand stand = (ArmorStand) ent; + // player.sendMessage(String.format("" + loc.getPitch())); + if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) { + return; + } + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (equipment != null) { + if (player instanceof Player) { + equipment.ShowFireLocation((Player) player); + } + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0)); - public void FirstShotDoAimDown(Entity ent, float amount, Entity player) { - Location loc = ent.getLocation(); - ArmorStand stand = (ArmorStand) ent; - // player.sendMessage(String.format("" + loc.getPitch())); - if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) { - return; - } - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (equipment != null) { - if (player instanceof Player) { - equipment.ShowFireLocation((Player)player); - } - if (equipment.RotateStandHead) { - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + } + } + loc.setPitch((float) (loc.getPitch() + amount)); - } - } - loc.setPitch((float) (loc.getPitch() + amount)); + ent.teleport(loc); + } - ent.teleport(loc); - } - NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); + NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); - @EventHandler - public void DeathEvent(EntityDeathEvent event) { - Boolean removeStands = false; - List items = event.getDrops(); - if (event.getEntity() instanceof ArmorStand) { - if (event.getEntity().getPersistentDataContainer().has(key, PersistentDataType.STRING)) { - Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING))); - base.remove(); - } - if (SiegeEngines.equipment.containsKey(event.getEntity().getUniqueId())) { - removeStands = true; - } - else { - for (ItemStack i : items) { - if (i.getType() == Material.CARVED_PUMPKIN && i.hasItemMeta() && i.getItemMeta().hasCustomModelData()) { - if (SiegeEngines.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) { - removeStands = true; - break; - } + @EventHandler + public void DeathEvent(EntityDeathEvent event) { + Boolean removeStands = false; + List items = event.getDrops(); + if (event.getEntity() instanceof ArmorStand) { + if (event.getEntity().getPersistentDataContainer().has(key, PersistentDataType.STRING)) { + Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING))); + base.remove(); + } + if (SiegeEngines.equipment.containsKey(event.getEntity().getUniqueId())) { + removeStands = true; + } else { + for (ItemStack i : items) { + if (i.getType() == Material.CARVED_PUMPKIN && i.hasItemMeta() && i.getItemMeta().hasCustomModelData()) { + if (SiegeEngines.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) { + removeStands = true; + break; + } - } - } - } - if (removeStands) { - for (ItemStack i : items) { - if (i.getType() == Material.ARMOR_STAND) { - i.setAmount(0); - return; - } - } - } - } - } + } + } + } + if (removeStands) { + for (ItemStack i : items) { + if (i.getType() == Material.ARMOR_STAND) { + i.setAmount(0); + return; + } + } + } + } + } - public void AimUp(Entity player, float amount) { + public void AimUp(Entity player, float amount) { - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent.isDead()) { - continue; - } - DoAimUp(ent, amount, player); - } - } + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent.isDead()) { + continue; + } + DoAimUp(ent, amount, player); + } + } - public void AimDown(Entity player, float amount) { + public void AimDown(Entity player, float amount) { - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent.isDead()) { - continue; - } - DoAimDown(ent, amount, player); - } - } + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent.isDead()) { + continue; + } + DoAimDown(ent, amount, player); + } + } - public void LoadCannonsWithPowder(Entity player) { - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent.isDead()) { - continue; - } + public void LoadCannonsWithPowder(Entity player) { + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent.isDead()) { + continue; + } - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (equipment != null) { - equipment.LoadFuel(player); - } - } - } + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (equipment != null) { + equipment.LoadFuel(player); + } + } + } - public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) { - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent.isDead()) { - continue; - } - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (equipment != null) { - equipment.LoadProjectile(player, projectile); - } - } - } + public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) { + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent.isDead()) { + continue; + } + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (equipment != null) { + equipment.LoadProjectile(player, projectile); + } + } + } - @EventHandler - public void onPlayerClickSign(PlayerInteractEvent event){ - Player player = event.getPlayer(); - if(event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")){ - Sign sign = (Sign) event.getClickedBlock().getState(); - if(sign.getLine(0).equalsIgnoreCase( "[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK){ - if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - return; - } - try { - Long delay = Long.parseLong(sign.getLine(1)); - if (delay < 6){ - delay = 6l; - } - Shoot((Entity)player, delay); - } catch (Exception e) { - Shoot((Entity)player, 6); - } - return; - } - if(sign.getLine(0).equalsIgnoreCase( "[Load]")){ - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - LoadCannonsWithPowder((Entity)player); - return; - } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - //load proj - ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (itemInHand == null) { - return; - } + @EventHandler + public void onPlayerClickSign(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")) { + Sign sign = (Sign) event.getClickedBlock().getState(); + if (sign.getLine(0).equalsIgnoreCase("[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + return; + } + try { + Long delay = Long.parseLong(sign.getLine(1)); + if (delay < 6) { + delay = 6l; + } + Shoot((Entity) player, delay); + } catch (Exception e) { + Shoot((Entity) player, 6); + } + return; + } + if (sign.getLine(0).equalsIgnoreCase("[Load]")) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + LoadCannonsWithPowder((Entity) player); + return; + } + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + //load proj + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + if (itemInHand == null) { + return; + } - LoadCannonsWithProjectile((Entity)player, player.getInventory().getItemInMainHand()); - return; - } - } + LoadCannonsWithProjectile((Entity) player, player.getInventory().getItemInMainHand()); + return; + } + } - if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){ - if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - return; - } - float amount; - try { - amount = Float.parseFloat(sign.getLine(1)); - if (player.isSneaking()) { - AimDown((Entity)player, amount); - } else { - AimUp((Entity)player, amount); - } - } catch (Exception e) { - // TODO Auto-generated catch block - player.sendMessage("§eCould not parse number on second line."); - } + if (sign.getLine(0).equalsIgnoreCase("[Aim]")) { + if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + return; + } + float amount; + try { + amount = Float.parseFloat(sign.getLine(1)); + if (player.isSneaking()) { + AimDown((Entity) player, amount); + } else { + AimUp((Entity) player, amount); + } + } catch (Exception e) { + // TODO Auto-generated catch block + player.sendMessage("§eCould not parse number on second line."); + } - return; - } + return; + } - if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){ - if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - SiegeEngines.TrackedStands.remove(player.getUniqueId()); - player.sendMessage("§eReleasing the equipment!"); - return; - } + if (sign.getLine(0).equalsIgnoreCase("[Cannon]")) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + SiegeEngines.TrackedStands.remove(player.getUniqueId()); + player.sendMessage("§eReleasing the equipment!"); + return; + } - if(event.getAction() == Action.RIGHT_CLICK_BLOCK){ - if (player.isSneaking()) { - SaveCannons(player, event.getClickedBlock()); - return; - } + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (player.isSneaking()) { + SaveCannons(player, event.getClickedBlock()); + return; + } - NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); - TileState state = (TileState) sign.getBlock().getState(); - SiegeEngines.TrackedStands.remove(player.getUniqueId()); - List temp = new ArrayList(); - if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { - return; - } - String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(","); - for (String s : split) { - temp.add(UUID.fromString(s.trim())); - } - for (UUID Id : temp) { - List entities = new ArrayList(); - Entity ent = Bukkit.getEntity(Id); - if (ent != null) { - TakeControl(player, ent); - } - } - player.sendMessage("§eNow controlling nearby equipment."); - return; - } - } + NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); + TileState state = (TileState) sign.getBlock().getState(); + SiegeEngines.TrackedStands.remove(player.getUniqueId()); + List temp = new ArrayList(); + if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { + return; + } + String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(","); + for (String s : split) { + temp.add(UUID.fromString(s.trim())); + } + for (UUID Id : temp) { + List entities = new ArrayList(); + Entity ent = Bukkit.getEntity(Id); + if (ent != null) { + TakeControl(player, ent); + } + } + player.sendMessage("§eNow controlling nearby equipment."); + return; + } + } - } - } + } + } - @EventHandler - public void onEntityClick(PlayerInteractAtEntityEvent event) { + @EventHandler + public void onEntityClick(PlayerInteractAtEntityEvent event) { - Player player = event.getPlayer(); - ItemStack itemInHand = player.getInventory().getItemInMainHand(); - Entity entity = event.getRightClicked(); - if (entity == null) { - return; - } - if (entity.getType() == EntityType.ARMOR_STAND){ - TakeControl(player, entity); - if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { - if (itemInHand.getType() == Material.CLOCK) { - if (player.isSneaking()) { - DoAimDown(entity, 1, player); - } - else { - DoAimUp(entity, 1, player); - } - return; - } - - GunnerEquipment equipment = SiegeEngines.equipment.get(entity.getUniqueId()); - event.setCancelled(true); - - if (itemInHand == null || itemInHand.getType() == Material.AIR) { - ArmorStand stand = (ArmorStand) entity; - if (stand.isInvisible()) { - stand.setInvisible(false); - player.sendMessage("§eEquipment is now breakable"); - } - else{ - if (equipment.AllowInvisibleStand) { - stand.setInvisible(true); - player.sendMessage("§eEquipment is no longer breakable"); - } - } - return; - } - if (itemInHand.isSimilar(equipment.FuelMaterial)) { - if (!equipment.LoadFuel(player)) { - player.sendMessage("§eCould not load Propellant."); - return; - } - } + Player player = event.getPlayer(); + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + Entity entity = event.getRightClicked(); + if (entity == null) { + return; + } + if (entity.getType() == EntityType.ARMOR_STAND) { + TakeControl(player, entity); + if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) { + if (itemInHand.getType() == Material.CLOCK) { + if (player.isSneaking()) { + DoAimDown(entity, 1, player); + } else { + DoAimUp(entity, 1, player); + } + return; + } + + GunnerEquipment equipment = SiegeEngines.equipment.get(entity.getUniqueId()); + event.setCancelled(true); + + if (itemInHand == null || itemInHand.getType() == Material.AIR) { + ArmorStand stand = (ArmorStand) entity; + if (stand.isInvisible()) { + stand.setInvisible(false); + player.sendMessage("§eEquipment is now breakable"); + } else { + if (equipment.AllowInvisibleStand) { + stand.setInvisible(true); + player.sendMessage("§eEquipment is no longer breakable"); + } + } + return; + } + if (itemInHand.isSimilar(equipment.FuelMaterial)) { + if (!equipment.LoadFuel(player)) { + player.sendMessage("§eCould not load Propellant."); + return; + } + } /*if (itemInHand.isSimilar(new ItemStack(Material.FLINT))) { if (equipment.isLoaded()) { equipment.Fire((Entity) player, 6, 1); @@ -741,19 +736,19 @@ public class ClickHandler implements Listener { } return; }*/ - for (ItemStack stack : equipment.Projectiles.keySet()) { - if (stack.isSimilar(itemInHand) && equipment.AmmoHolder.LoadedProjectile == 0){ - equipment.AmmoHolder.LoadedProjectile = 1; - equipment.AmmoHolder.MaterialName = stack; - player.sendMessage("§eAdding Ammo to Weapon"); - itemInHand.setAmount(itemInHand.getAmount() - 1); - return; - } + for (ItemStack stack : equipment.Projectiles.keySet()) { + if (stack.isSimilar(itemInHand) && equipment.AmmoHolder.LoadedProjectile == 0) { + equipment.AmmoHolder.LoadedProjectile = 1; + equipment.AmmoHolder.MaterialName = stack; + player.sendMessage("§eAdding Ammo to Weapon"); + itemInHand.setAmount(itemInHand.getAmount() - 1); + return; + } - } - player.sendMessage("§eNow controlling this equipment."); - return; - } - } - } + } + player.sendMessage("§eNow controlling this equipment."); + return; + } + } + } } diff --git a/src/main/java/com/github/alathra/siegeengines/listeners/RotationHandler.java b/src/main/java/com/github/alathra/siegeengines/listeners/RotationHandler.java index 8564afc..b9b3aba 100644 --- a/src/main/java/com/github/alathra/siegeengines/listeners/RotationHandler.java +++ b/src/main/java/com/github/alathra/siegeengines/listeners/RotationHandler.java @@ -23,74 +23,74 @@ import com.github.alathra.siegeengines.GunnerEquipment; public class RotationHandler implements Listener { - @EventHandler - public void playerMove(PlayerMoveEvent event) { - Player player = event.getPlayer(); - NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); - if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { - ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (itemInHand != null) { - if (itemInHand.getType() != Material.COMPASS) { - // TrackedStands.remove(player.getUniqueId()); + @EventHandler + public void playerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons"); + if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) { + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + if (itemInHand != null) { + if (itemInHand.getType() != Material.COMPASS) { + // TrackedStands.remove(player.getUniqueId()); - return; - } - for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { - if (ent != null) { - GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); - if (ent.isDead()) { - continue; - } - double distance = player.getLocation().distance(ent.getLocation()); - if (distance <= 250) { - // player.sendMessage("§egot id"); - LivingEntity living = (LivingEntity) ent; - Location loc = ent.getLocation(); - - if (equipment.RotateSideways) { - Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50)); + return; + } + for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) { + if (ent != null) { + GunnerEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId()); + if (ent.isDead()) { + continue; + } + double distance = player.getLocation().distance(ent.getLocation()); + if (distance <= 250) { + // player.sendMessage("§egot id"); + LivingEntity living = (LivingEntity) ent; + Location loc = ent.getLocation(); - Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector()); - if (ent.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { - Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING))); - Location baseloc = base.getLocation(); - baseloc.setDirection(dirBetweenLocations); - base.teleport(baseloc); - } - loc.setDirection(dirBetweenLocations); - } - //loc.setYaw(player.getLocation().getYaw()); - //loc.setPitch(player.getLocation().getPitch()); - - - ArmorStand stand = (ArmorStand) living; - - if (equipment.RotateUpDown) { - loc.setPitch(player.getLocation().getPitch()); - if (loc.getPitch() < -85) { - loc.setPitch(-85); - } - if (loc.getPitch() > 85) { - loc.setPitch(85); - } - if (equipment.RotateStandHead) { - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); - } - } - - - living.teleport(loc); - equipment.ShowFireLocation(player); - } - } - } - } - } - } - - Vector getDirectionBetweenLocations(Location Start, Location End) { - Vector from = Start.toVector(); - Vector to = End.toVector(); - return to.subtract(from); - } + if (equipment.RotateSideways) { + Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50)); + + Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector()); + if (ent.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { + Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING))); + Location baseloc = base.getLocation(); + baseloc.setDirection(dirBetweenLocations); + base.teleport(baseloc); + } + loc.setDirection(dirBetweenLocations); + } + //loc.setYaw(player.getLocation().getYaw()); + //loc.setPitch(player.getLocation().getPitch()); + + + ArmorStand stand = (ArmorStand) living; + + if (equipment.RotateUpDown) { + loc.setPitch(player.getLocation().getPitch()); + if (loc.getPitch() < -85) { + loc.setPitch(-85); + } + if (loc.getPitch() > 85) { + loc.setPitch(85); + } + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0)); + } + } + + + living.teleport(loc); + equipment.ShowFireLocation(player); + } + } + } + } + } + } + + Vector getDirectionBetweenLocations(Location Start, Location End) { + Vector from = Start.toVector(); + Vector to = End.toVector(); + return to.subtract(from); + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java index 0479a37..16958e1 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java @@ -12,78 +12,79 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.util.Vector; -public class EntityProjectile implements GunnersProjectile{ +public class EntityProjectile implements GunnersProjectile { - public String ProjectileType = "Entity"; - public int EntityCount = 20; - public int ArrowOnlyDamage = 6; - public Boolean DelayedFire = false; - public int DelayTime = 6; - public EntityType EntityTyp = EntityType.ARROW; - public float Inaccuracy = 0.2f; - public Particle ParticleType = Particle.EXPLOSION_LARGE; - public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - @Override - public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) { - PlaySound = true; - int baseDelay = 0; - for (int i = 0; i < EntityCount; i++) { - if (DelayedFire) { - baseDelay += DelayTime; - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { - - CreateEntity(entity, FireLocation, velocity, player); - }, (long) baseDelay); - } - else { + public String ProjectileType = "Entity"; + public int EntityCount = 20; + public int ArrowOnlyDamage = 6; + public Boolean DelayedFire = false; + public int DelayTime = 6; + public EntityType EntityTyp = EntityType.ARROW; + public float Inaccuracy = 0.2f; + public Particle ParticleType = Particle.EXPLOSION_LARGE; + public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - CreateEntity(entity, FireLocation, velocity, player); - } - - // } - } - } - private boolean PlaySound = true; - private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) { - World world = entity.getLocation().getWorld(); - LivingEntity living = (LivingEntity) entity; + @Override + public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) { + PlaySound = true; + int baseDelay = 0; + for (int i = 0; i < EntityCount; i++) { + if (DelayedFire) { + baseDelay += DelayTime; + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { - Entity arrow = world.spawnEntity(loc, EntityTyp); - if (Inaccuracy != 0f) { - arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) - .subtract(Randomise())); - } - else { - arrow.setVelocity(loc.getDirection().multiply(velocity)); - } - arrow.setMetadata("isEntityProj",SiegeEngines.addMetaDataValue("true")); - Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow)); - - if (arrow instanceof org.bukkit.entity.Projectile) { - if (player instanceof org.bukkit.projectiles.ProjectileSource) - ((org.bukkit.entity.Projectile)arrow).setShooter((org.bukkit.projectiles.ProjectileSource)player); - } - if (arrow instanceof Arrow) { - Arrow arr = (Arrow) arrow; - arr.setDamage(8); - if (player instanceof org.bukkit.projectiles.ProjectileSource) - arr.setShooter((org.bukkit.projectiles.ProjectileSource)player); - //arr.setBasePotionData(arg0); - } - // MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET); - // DisguiseAPI.disguiseEntity(arrow, miscDisguise); - if (PlaySound) { - world.playSound(loc, this.SoundType, 20, 2); - world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); - if (!DelayedFire) { - PlaySound = false; - } - } + CreateEntity(entity, FireLocation, velocity, player); + }, (long) baseDelay); + } else { - } - - private Vector Randomise() { - return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); - } + CreateEntity(entity, FireLocation, velocity, player); + } + + // } + } + } + + private boolean PlaySound = true; + + private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) { + World world = entity.getLocation().getWorld(); + LivingEntity living = (LivingEntity) entity; + + Entity arrow = world.spawnEntity(loc, EntityTyp); + if (Inaccuracy != 0f) { + arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) + .subtract(Randomise())); + } else { + arrow.setVelocity(loc.getDirection().multiply(velocity)); + } + arrow.setMetadata("isEntityProj", SiegeEngines.addMetaDataValue("true")); + Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow)); + + if (arrow instanceof org.bukkit.entity.Projectile) { + if (player instanceof org.bukkit.projectiles.ProjectileSource) + ((org.bukkit.entity.Projectile) arrow).setShooter((org.bukkit.projectiles.ProjectileSource) player); + } + if (arrow instanceof Arrow) { + Arrow arr = (Arrow) arrow; + arr.setDamage(8); + if (player instanceof org.bukkit.projectiles.ProjectileSource) + arr.setShooter((org.bukkit.projectiles.ProjectileSource) player); + //arr.setBasePotionData(arg0); + } + // MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET); + // DisguiseAPI.disguiseEntity(arrow, miscDisguise); + if (PlaySound) { + world.playSound(loc, this.SoundType, 20, 2); + world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); + if (!DelayedFire) { + PlaySound = false; + } + } + + } + + private Vector Randomise() { + return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java index b219b52..1744c1c 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java @@ -17,74 +17,73 @@ import org.bukkit.util.Vector; //import me.libraryaddict.disguise.disguisetypes.MiscDisguise; public class ExplosiveProjectile implements GunnersProjectile { - - public String ProjectileType = "Explosive"; - public Boolean PlaceBlocks = false; - public Material BlockToPlace = Material.COBWEB; - public int BlocksToPlaceAmount = 3; - public float ExplodePower = 2; - public float Inaccuracy = 0.3f; - public int ProjectilesCount = 1; - public Boolean DelayedFire = false; - public int DelayTime = 6; - public Particle ParticleType = Particle.EXPLOSION_LARGE; - public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - private boolean PlaySound = true; - public Boolean AlertOnLanding = false; - @Override - public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { - PlaySound = true; - int baseDelay = 0; - for (int i = 0; i < ProjectilesCount; i++) { - if (DelayedFire) { - baseDelay += DelayTime; - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { - CreateEntity(entity, loc, velocity, player); - }, (long) baseDelay); - } - else { - CreateEntity(entity,loc, velocity, player); - } - - // } - } - } - private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) { - LivingEntity living = (LivingEntity) entity; - World world = entity.getLocation().getWorld(); - Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL); - Snowball ball = (Snowball) tnt; - if (player instanceof org.bukkit.projectiles.ProjectileSource) - ball.setShooter((org.bukkit.projectiles.ProjectileSource)player); - ClickHandler.projectiles.put(tnt.getUniqueId(), this); - - if (Inaccuracy != 0f) { - tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) - .subtract(Randomise())); - } - else { - tnt.setVelocity(loc.getDirection().multiply(velocity)); - } - tnt.setMetadata("isExplosiveProj",SiegeEngines.addMetaDataValue("true")); - Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt)); + public String ProjectileType = "Explosive"; + public Boolean PlaceBlocks = false; + public Material BlockToPlace = Material.COBWEB; + public int BlocksToPlaceAmount = 3; + public float ExplodePower = 2; + public float Inaccuracy = 0.3f; + public int ProjectilesCount = 1; + public Boolean DelayedFire = false; + public int DelayTime = 6; + public Particle ParticleType = Particle.EXPLOSION_LARGE; + public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; + private boolean PlaySound = true; + public Boolean AlertOnLanding = false; - if (PlaySound) { - world.playSound(loc, this.SoundType, 20, 2); - world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); - if (!DelayedFire) { - PlaySound = false; - } - } + @Override + public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { + PlaySound = true; + int baseDelay = 0; + for (int i = 0; i < ProjectilesCount; i++) { + if (DelayedFire) { + baseDelay += DelayTime; + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { + CreateEntity(entity, loc, velocity, player); + }, (long) baseDelay); + } else { + CreateEntity(entity, loc, velocity, player); + } + + // } + } + } + + private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) { + LivingEntity living = (LivingEntity) entity; + World world = entity.getLocation().getWorld(); + Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL); + Snowball ball = (Snowball) tnt; + if (player instanceof org.bukkit.projectiles.ProjectileSource) + ball.setShooter((org.bukkit.projectiles.ProjectileSource) player); + ClickHandler.projectiles.put(tnt.getUniqueId(), this); + + if (Inaccuracy != 0f) { + tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) + .subtract(Randomise())); + } else { + tnt.setVelocity(loc.getDirection().multiply(velocity)); + } + tnt.setMetadata("isExplosiveProj", SiegeEngines.addMetaDataValue("true")); + Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt)); + + if (PlaySound) { + world.playSound(loc, this.SoundType, 20, 2); + world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); + if (!DelayedFire) { + PlaySound = false; + } + } // MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.ARROW); // miscDisguise.setEntity(tnt); // miscDisguise.startDisguise(); - } - - private Vector Randomise() { - return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); - } + } + + private Vector Randomise() { + return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java index c56c752..ce06a07 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java @@ -4,7 +4,8 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; public interface GunnersProjectile { - public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity); - public String ProjectileType = "Default"; + public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity); + + public String ProjectileType = "Default"; } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java index f47030f..2d7c475 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java @@ -18,58 +18,57 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; public class PotionProjectile implements GunnersProjectile { - public String ProjectileType = "Potion"; - public int EntityCount = 3; - public Boolean DelayedFire = false; - public int DelayTime = 6; - public float Inaccuracy = 0.1f; - public Particle ParticleType = Particle.EXPLOSION_LARGE; - public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - - @Override - public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { - //TODO Auto-generated method stub - int baseDelay = 0; - for (int i = 0; i < EntityCount; i++) { - if (DelayedFire) { - baseDelay += DelayTime; - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { - - CreateEntity(entity,loc, velocity); - }, (long) baseDelay); - } - else { - CreateEntity(entity, loc, velocity); - } - // } - } - } - private void CreateEntity(Entity entity, Location loc, Float velocity) { - World world = entity.getLocation().getWorld(); - LivingEntity living = (LivingEntity) entity; + public String ProjectileType = "Potion"; + public int EntityCount = 3; + public Boolean DelayedFire = false; + public int DelayTime = 6; + public float Inaccuracy = 0.1f; + public Particle ParticleType = Particle.EXPLOSION_LARGE; + public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION); - if (Inaccuracy != 0f) { - arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()).subtract(Randomise())); - } - else { - arrow.setVelocity(loc.getDirection().multiply(velocity)); - } - arrow.setMetadata("isExplosiveProj",SiegeEngines.addMetaDataValue("true")); - Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow)); - ItemStack itemStack = new ItemStack(Material.SPLASH_POTION); - PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); - potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 100, 3, true), true); - itemStack.setItemMeta(potionMeta); - ThrownPotion potion = (ThrownPotion) arrow; - potion.setItem(itemStack); - // MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET); - // DisguiseAPI.disguiseEntity(arrow, miscDisguise); - world.playSound(loc, this.SoundType, 20, 2); - world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); - } - - private Vector Randomise() { - return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); - } + @Override + public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { + //TODO Auto-generated method stub + int baseDelay = 0; + for (int i = 0; i < EntityCount; i++) { + if (DelayedFire) { + baseDelay += DelayTime; + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> { + + CreateEntity(entity, loc, velocity); + }, (long) baseDelay); + } else { + CreateEntity(entity, loc, velocity); + } + // } + } + } + + private void CreateEntity(Entity entity, Location loc, Float velocity) { + World world = entity.getLocation().getWorld(); + LivingEntity living = (LivingEntity) entity; + + Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION); + if (Inaccuracy != 0f) { + arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()).subtract(Randomise())); + } else { + arrow.setVelocity(loc.getDirection().multiply(velocity)); + } + arrow.setMetadata("isExplosiveProj", SiegeEngines.addMetaDataValue("true")); + Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow)); + ItemStack itemStack = new ItemStack(Material.SPLASH_POTION); + PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); + potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 100, 3, true), true); + itemStack.setItemMeta(potionMeta); + ThrownPotion potion = (ThrownPotion) arrow; + potion.setItem(itemStack); + // MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET); + // DisguiseAPI.disguiseEntity(arrow, miscDisguise); + world.playSound(loc, this.SoundType, 20, 2); + world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); + } + + private Vector Randomise() { + return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 06dc365..d5941b6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,9 +3,9 @@ main: "com.github.alathra.siegeengines.SiegeEngines" version: "${project.version}" api-version: "1.19" libraries: - - org.apache.commons:commons-math3:3.6.1 + - org.apache.commons:commons-math3:3.6.1 commands: - SiegeEngines: - description: "SiegeEngines Commands" - default: false - usage: "SiegeEngines" + SiegeEngines: + description: "SiegeEngines Commands" + default: false + usage: "SiegeEngines"