mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
145 Commits
v1.2.4+1.2
...
v2.0.2+1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
067cd5c731
|
|||
|
1eed415053
|
|||
|
42cef73318
|
|||
|
266d56ed93
|
|||
|
423ee4e694
|
|||
|
7cf5b8e1d6
|
|||
|
e9bdfaefca
|
|||
|
e1773d4d79
|
|||
|
84da16fae6
|
|||
|
ac9189ecdc
|
|||
|
7131cb76d0
|
|||
|
4943c7d8f6
|
|||
|
82baf0b63e
|
|||
|
c755417ebf
|
|||
|
6cf7d0c465
|
|||
|
20feec931f
|
|||
|
73ffc37f2d
|
|||
|
726f4ed7a8
|
|||
|
fbbc37e4b1
|
|||
|
19114de347
|
|||
|
455d0deddc
|
|||
|
0eaaf6a950
|
|||
|
7c8aba6f71
|
|||
|
99675bb5ee
|
|||
|
6ad656c388
|
|||
|
fece751f0f
|
|||
|
ab75eddc90
|
|||
|
f9aa3f664a
|
|||
|
9edbb21128
|
|||
|
4851687fc9
|
|||
|
7bceb0d5ed
|
|||
|
65957b61c5
|
|||
|
|
8c3d1fe831 | ||
|
|
1dc1789fa4 | ||
|
|
85a0fa760b | ||
|
|
0a00b40655 | ||
|
f98808583d
|
|||
|
21c98a4224
|
|||
|
727fb7880f
|
|||
|
3ed9c67faa
|
|||
|
b6b10c1e9e
|
|||
|
399636e1ae
|
|||
|
3e88781186
|
|||
|
686d659126
|
|||
|
8f20c6a68a
|
|||
|
dd3c5ac58d
|
|||
|
3e8463c4ce
|
|||
|
ed8e961067
|
|||
|
1b36f6465c
|
|||
|
b1d2d1de7b
|
|||
|
f7e486cd24
|
|||
|
0294661375
|
|||
|
a555d61940
|
|||
|
a14f39a766
|
|||
|
952ec5b669
|
|||
|
d474c7902f
|
|||
|
b3c4340b89
|
|||
|
ca55fe845d
|
|||
|
8280c501cf
|
|||
|
baa9a93386
|
|||
|
2389b774e7
|
|||
|
af72f3eefd
|
|||
|
aa8086c417
|
|||
|
a4b4297af2
|
|||
|
a50c6e431c
|
|||
|
639901667f
|
|||
|
4969d171b7
|
|||
|
299601998d
|
|||
|
d07edf6913
|
|||
|
845c13dca5
|
|||
|
cd7e8c58c9
|
|||
|
d4746fcc0c
|
|||
|
56f05f5a88
|
|||
|
9b4406d840
|
|||
|
45840e0418
|
|||
|
abefad1f39
|
|||
|
b9699486ab
|
|||
|
bed53909a8
|
|||
|
799ec9d52e
|
|||
|
9733490dd0
|
|||
|
972bd4c8d8
|
|||
|
82f078bfdb
|
|||
|
f567996ced
|
|||
|
a8bc27395e
|
|||
|
440deda2ef
|
|||
|
18b0d6bd8e
|
|||
|
2f674abb01
|
|||
|
f6d9b26413
|
|||
|
1a7cea803f
|
|||
|
8febe5c496
|
|||
|
35a2c60161
|
|||
|
badc8c3494
|
|||
|
9ddfa334ea
|
|||
|
dbb7c19f10
|
|||
|
7b6937bf8e
|
|||
|
9816796cae
|
|||
|
c352560689
|
|||
|
5b918f4b90
|
|||
|
e45de1e180
|
|||
|
1f9e1b8f1e
|
|||
|
03a694bde2
|
|||
|
d59bff14c9
|
|||
|
fbb15a2dab
|
|||
|
e50035abc7
|
|||
|
f7bcca2476
|
|||
|
bdbf3e6748
|
|||
|
07e3aaf60c
|
|||
|
59ecc5a56a
|
|||
|
0ca106c3f5
|
|||
|
e4e1ff874d
|
|||
|
80f481ddd2
|
|||
|
e9784e6bd5
|
|||
|
74fb9798b4
|
|||
|
b3c1fa1c34
|
|||
|
a15cbdd512
|
|||
|
257068d37f
|
|||
|
c663423f33
|
|||
|
63fa9bfb98
|
|||
|
818a3439f1
|
|||
|
0890e369b4
|
|||
|
4cd0df4634
|
|||
|
1ef5cb4082
|
|||
|
e114ac2b37
|
|||
|
0c9b4d44cb
|
|||
|
2fca98e0f2
|
|||
|
3cba252b5b
|
|||
|
592cfb6ca4
|
|||
|
|
decad54884 | ||
|
3dd75626a1
|
|||
|
d720fc52ef
|
|||
|
b3a618f50b
|
|||
|
8724d6dd41
|
|||
|
baa1228f23
|
|||
|
16dc4bdc50
|
|||
|
ed3bc666db
|
|||
|
694aca9825
|
|||
|
7e38f06a84
|
|||
|
cd48efb3d2
|
|||
|
1ad0a2bd3a
|
|||
|
5e12356940
|
|||
|
|
43e775f53a | ||
|
|
25eeeb2c30 | ||
|
|
e11696fe96 | ||
|
|
8935ba0028 | ||
|
|
24eef36890 |
262
.editorconfig
Normal file
262
.editorconfig
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = crlf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
tab_width = 4
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
ij_continuation_indent_size = 8
|
||||||
|
|
||||||
|
[*.properties]
|
||||||
|
ij_any_keep_blank_lines_in_code = unset
|
||||||
|
|
||||||
|
[*.java]
|
||||||
|
ij_java_align_consecutive_assignments = false
|
||||||
|
ij_java_align_consecutive_variable_declarations = false
|
||||||
|
ij_java_align_group_field_declarations = false
|
||||||
|
ij_java_align_multiline_annotation_parameters = true
|
||||||
|
ij_java_align_multiline_array_initializer_expression = false
|
||||||
|
ij_java_align_multiline_assignment = false
|
||||||
|
ij_java_align_multiline_binary_operation = true
|
||||||
|
ij_java_align_multiline_chained_methods = false
|
||||||
|
ij_java_align_multiline_extends_list = false
|
||||||
|
ij_java_align_multiline_for = true
|
||||||
|
ij_java_align_multiline_method_parentheses = false
|
||||||
|
ij_java_align_multiline_parameters = false
|
||||||
|
ij_java_align_multiline_parameters_in_calls = false
|
||||||
|
ij_java_align_multiline_parenthesized_expression = false
|
||||||
|
ij_java_align_multiline_records = true
|
||||||
|
ij_java_align_multiline_resources = true
|
||||||
|
ij_java_align_multiline_ternary_operation = false
|
||||||
|
ij_java_align_multiline_text_blocks = false
|
||||||
|
ij_java_align_multiline_throws_list = false
|
||||||
|
ij_java_align_subsequent_simple_methods = false
|
||||||
|
ij_java_align_throws_keyword = false
|
||||||
|
ij_java_annotation_parameter_wrap = normal
|
||||||
|
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_at_first_column = true
|
||||||
|
ij_java_call_parameters_new_line_after_left_paren = false
|
||||||
|
ij_java_call_parameters_right_paren_on_new_line = false
|
||||||
|
ij_java_call_parameters_wrap = 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_do_not_indent_top_level_class_members = false
|
||||||
|
ij_java_do_not_wrap_after_single_annotation = 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_entity_dd_suffix = EJB
|
||||||
|
ij_java_entity_eb_suffix = Bean
|
||||||
|
ij_java_entity_hi_suffix = Home
|
||||||
|
ij_java_entity_lhi_prefix = Local
|
||||||
|
ij_java_entity_lhi_suffix = Home
|
||||||
|
ij_java_entity_li_prefix = Local
|
||||||
|
ij_java_entity_pk_class = java.lang.String
|
||||||
|
ij_java_entity_vo_suffix = VO
|
||||||
|
ij_java_enum_constants_wrap = split_into_lines
|
||||||
|
ij_java_extends_keyword_wrap = off
|
||||||
|
ij_java_extends_list_wrap = off
|
||||||
|
ij_java_field_annotation_wrap = on_every_item
|
||||||
|
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_control_statement_in_one_line = true
|
||||||
|
ij_java_keep_first_column_comment = true
|
||||||
|
ij_java_keep_indents_on_empty_lines = true
|
||||||
|
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 = true
|
||||||
|
ij_java_keep_simple_lambdas_in_one_line = true
|
||||||
|
ij_java_keep_simple_methods_in_one_line = true
|
||||||
|
ij_java_label_indent_absolute = false
|
||||||
|
ij_java_label_indent_size = 0
|
||||||
|
ij_java_lambda_brace_style = end_of_line
|
||||||
|
ij_java_layout_static_imports_separately = true
|
||||||
|
ij_java_line_comment_add_space = false
|
||||||
|
ij_java_line_comment_at_first_column = true
|
||||||
|
ij_java_message_dd_suffix = EJB
|
||||||
|
ij_java_message_eb_suffix = Bean
|
||||||
|
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_names_count_to_use_import_on_demand = 3
|
||||||
|
ij_java_new_line_after_lparen_in_record_header = false
|
||||||
|
ij_java_parameter_annotation_wrap = normal
|
||||||
|
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_synchronized = true
|
||||||
|
ij_java_replace_instanceof_and_cast = false
|
||||||
|
ij_java_replace_null_check = true
|
||||||
|
ij_java_replace_sum_lambda_with_method_ref = true
|
||||||
|
ij_java_resource_list_new_line_after_left_paren = false
|
||||||
|
ij_java_resource_list_right_paren_on_new_line = false
|
||||||
|
ij_java_resource_list_wrap = off
|
||||||
|
ij_java_rparen_on_new_line_in_record_header = false
|
||||||
|
ij_java_session_dd_suffix = EJB
|
||||||
|
ij_java_session_eb_suffix = Bean
|
||||||
|
ij_java_session_hi_suffix = Home
|
||||||
|
ij_java_session_lhi_prefix = Local
|
||||||
|
ij_java_session_lhi_suffix = Home
|
||||||
|
ij_java_session_li_prefix = Local
|
||||||
|
ij_java_session_si_suffix = Service
|
||||||
|
ij_java_space_after_closing_angle_bracket_in_type_argument = false
|
||||||
|
ij_java_space_after_colon = true
|
||||||
|
ij_java_space_after_comma = true
|
||||||
|
ij_java_space_after_comma_in_type_arguments = true
|
||||||
|
ij_java_space_after_for_semicolon = true
|
||||||
|
ij_java_space_after_quest = true
|
||||||
|
ij_java_space_after_type_cast = true
|
||||||
|
ij_java_space_before_annotation_array_initializer_left_brace = false
|
||||||
|
ij_java_space_before_annotation_parameter_list = false
|
||||||
|
ij_java_space_before_array_initializer_left_brace = false
|
||||||
|
ij_java_space_before_catch_keyword = true
|
||||||
|
ij_java_space_before_catch_left_brace = true
|
||||||
|
ij_java_space_before_catch_parentheses = true
|
||||||
|
ij_java_space_before_class_left_brace = true
|
||||||
|
ij_java_space_before_colon = true
|
||||||
|
ij_java_space_before_colon_in_foreach = true
|
||||||
|
ij_java_space_before_comma = false
|
||||||
|
ij_java_space_before_do_left_brace = true
|
||||||
|
ij_java_space_before_else_keyword = true
|
||||||
|
ij_java_space_before_else_left_brace = true
|
||||||
|
ij_java_space_before_finally_keyword = true
|
||||||
|
ij_java_space_before_finally_left_brace = true
|
||||||
|
ij_java_space_before_for_left_brace = true
|
||||||
|
ij_java_space_before_for_parentheses = true
|
||||||
|
ij_java_space_before_for_semicolon = false
|
||||||
|
ij_java_space_before_if_left_brace = true
|
||||||
|
ij_java_space_before_if_parentheses = true
|
||||||
|
ij_java_space_before_method_call_parentheses = false
|
||||||
|
ij_java_space_before_method_left_brace = true
|
||||||
|
ij_java_space_before_method_parentheses = false
|
||||||
|
ij_java_space_before_opening_angle_bracket_in_type_parameter = false
|
||||||
|
ij_java_space_before_quest = true
|
||||||
|
ij_java_space_before_switch_left_brace = true
|
||||||
|
ij_java_space_before_switch_parentheses = true
|
||||||
|
ij_java_space_before_synchronized_left_brace = true
|
||||||
|
ij_java_space_before_synchronized_parentheses = true
|
||||||
|
ij_java_space_before_try_left_brace = true
|
||||||
|
ij_java_space_before_try_parentheses = true
|
||||||
|
ij_java_space_before_type_parameter_list = false
|
||||||
|
ij_java_space_before_while_keyword = true
|
||||||
|
ij_java_space_before_while_left_brace = true
|
||||||
|
ij_java_space_before_while_parentheses = true
|
||||||
|
ij_java_space_inside_one_line_enum_braces = false
|
||||||
|
ij_java_space_within_empty_array_initializer_braces = false
|
||||||
|
ij_java_space_within_empty_method_call_parentheses = false
|
||||||
|
ij_java_space_within_empty_method_parentheses = false
|
||||||
|
ij_java_spaces_around_additive_operators = true
|
||||||
|
ij_java_spaces_around_assignment_operators = true
|
||||||
|
ij_java_spaces_around_bitwise_operators = true
|
||||||
|
ij_java_spaces_around_equality_operators = true
|
||||||
|
ij_java_spaces_around_lambda_arrow = true
|
||||||
|
ij_java_spaces_around_logical_operators = true
|
||||||
|
ij_java_spaces_around_method_ref_dbl_colon = false
|
||||||
|
ij_java_spaces_around_multiplicative_operators = true
|
||||||
|
ij_java_spaces_around_relational_operators = true
|
||||||
|
ij_java_spaces_around_shift_operators = true
|
||||||
|
ij_java_spaces_around_type_bounds_in_type_parameters = true
|
||||||
|
ij_java_spaces_around_unary_operator = false
|
||||||
|
ij_java_spaces_within_angle_brackets = false
|
||||||
|
ij_java_spaces_within_annotation_parentheses = false
|
||||||
|
ij_java_spaces_within_array_initializer_braces = false
|
||||||
|
ij_java_spaces_within_braces = false
|
||||||
|
ij_java_spaces_within_brackets = false
|
||||||
|
ij_java_spaces_within_cast_parentheses = false
|
||||||
|
ij_java_spaces_within_catch_parentheses = false
|
||||||
|
ij_java_spaces_within_for_parentheses = false
|
||||||
|
ij_java_spaces_within_if_parentheses = false
|
||||||
|
ij_java_spaces_within_method_call_parentheses = false
|
||||||
|
ij_java_spaces_within_method_parentheses = false
|
||||||
|
ij_java_spaces_within_parentheses = false
|
||||||
|
ij_java_spaces_within_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_subclass_name_suffix = Impl
|
||||||
|
ij_java_ternary_operation_signs_on_next_line = false
|
||||||
|
ij_java_ternary_operation_wrap = off
|
||||||
|
ij_java_test_name_suffix = Test
|
||||||
|
ij_java_throws_keyword_wrap = normal
|
||||||
|
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 = normal
|
||||||
|
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
|
||||||
51
.github/workflows/build.yml
vendored
51
.github/workflows/build.yml
vendored
@@ -1,20 +1,41 @@
|
|||||||
name: Compiling
|
name: build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '*.md'
|
||||||
|
tags-ignore:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '*.md'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 21
|
||||||
|
|
||||||
steps:
|
- name: Setup Gradle
|
||||||
- name: Compile
|
uses: gradle/actions/setup-gradle@v3
|
||||||
uses: Ruochenfu2011/compilation@v1
|
with:
|
||||||
|
cache-read-only: false
|
||||||
- name: Archive Artifacts
|
|
||||||
uses: actions/upload-artifact@v2
|
- name: Change wrapper permissions
|
||||||
with:
|
run: chmod +x ./gradlew
|
||||||
name: Artifacts
|
|
||||||
path: ./build/libs
|
- name: Run build with Gradle Wrapper
|
||||||
|
run: ./gradlew build
|
||||||
|
|
||||||
|
- name: Upload built JARs
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: skin-restorer-artifacts
|
||||||
|
path: ./*/build/libs/*.jar
|
||||||
|
|||||||
39
.github/workflows/release.yml
vendored
Normal file
39
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
name: release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
environment: release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 21
|
||||||
|
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v3
|
||||||
|
with:
|
||||||
|
cache-read-only: false
|
||||||
|
|
||||||
|
- name: Change wrapper permissions
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
|
||||||
|
- name: Publish to CurseForge, Modrinth
|
||||||
|
run: ./gradlew build publishMods
|
||||||
|
env:
|
||||||
|
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
|
||||||
|
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||||
|
|
||||||
|
- name: Upload built JARs
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: skin-restorer-artifacts
|
||||||
|
path: ./*/build/libs/*.jar
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -28,6 +28,5 @@ bin/
|
|||||||
|
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
# fabric
|
.architectury-transformer/
|
||||||
|
|
||||||
run/
|
run/
|
||||||
|
|||||||
70
CHANGELOG.md
Normal file
70
CHANGELOG.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Changelog
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.0.2] - 2024-08-04
|
||||||
|
### Added
|
||||||
|
- Backported to minecraft 1.20-1.20.2
|
||||||
|
- [Forge] Added support for Forge
|
||||||
|
### Changed
|
||||||
|
- Changed minimum java version to 17 for minecraft 1.20-1.20.4
|
||||||
|
|
||||||
|
## [2.0.1] - 2024-07-16
|
||||||
|
### Added
|
||||||
|
- Added Traditional Chinese translation ([#24](https://github.com/Suiranoil/SkinRestorer/pull/24)) - *yichifauzi*, *notlin4*
|
||||||
|
### Fixed
|
||||||
|
- Fixed concurrent modification exception
|
||||||
|
|
||||||
|
## [2.0.0] - 2024-07-03
|
||||||
|
### Added
|
||||||
|
- Added support for NeoForge
|
||||||
|
- Added support for singleplayer
|
||||||
|
- Added ely.by skin provider
|
||||||
|
- Added `/skin refresh` command to get up-to-date skin
|
||||||
|
- Added `/skin reset` command to remove skin data
|
||||||
|
- Added proper support for secure servers
|
||||||
|
- Added support for permissions api
|
||||||
|
- Added translations
|
||||||
|
### Changed
|
||||||
|
- Changed to save skin data per world
|
||||||
|
### Fixed
|
||||||
|
- Fixed entity flickering on skin reload
|
||||||
|
- Fixed player being left in invalid state on skin reload if on death screen
|
||||||
|
|
||||||
|
## [1.2.6] - 2024-06-25
|
||||||
|
### Added
|
||||||
|
- Added support for command blocks
|
||||||
|
### Changed
|
||||||
|
- Changed to better skin refresh logic
|
||||||
|
### Fixed
|
||||||
|
- Fixed no permission level for /skin clear targets
|
||||||
|
- Fixed loading world screen on skin change
|
||||||
|
|
||||||
|
## [1.2.4] - 2023-09-30
|
||||||
|
### Fixed
|
||||||
|
- Fixed player stops riding entity with skin change
|
||||||
|
- Fixed armor and hand items not displaying with skin change
|
||||||
|
|
||||||
|
## [1.2.3] - 2023-06-10
|
||||||
|
### Changed
|
||||||
|
- Updated to 1.20-1.20.1
|
||||||
|
|
||||||
|
## [1.2.2] - 2022-12-21
|
||||||
|
### Changed
|
||||||
|
- Updated to 1.19.3
|
||||||
|
|
||||||
|
## [1.2.1] - 2022-11-24
|
||||||
|
### Fixed
|
||||||
|
- Fixed incorrect filepath resolvement on linux systems
|
||||||
|
|
||||||
|
## [1.2.0] - 2022-11-18
|
||||||
|
### Added
|
||||||
|
- Added support for fake players ([#4](https://github.com/Suiranoil/SkinRestorer/pull/4)) - *CaveNightingale*
|
||||||
|
### Changed
|
||||||
|
- Allow player to apply their skin changes immediately ([#4](https://github.com/Suiranoil/SkinRestorer/pull/4)) - _CaveNightingale_
|
||||||
|
|
||||||
|
## [1.0.4] - 2021-08-28
|
||||||
|
### Fixed
|
||||||
|
- Fixed "invalid player data" exception
|
||||||
5
CHANGELOG_LATEST.md
Normal file
5
CHANGELOG_LATEST.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
### Added
|
||||||
|
- Backported to minecraft 1.20-1.20.2
|
||||||
|
- [Forge] Added support for Forge
|
||||||
|
### Changed
|
||||||
|
- Changed minimum java version to 17 for minecraft 1.20-1.20.4
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2021 LionariusPy
|
Copyright (c) 2021-2024 Lionarius
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
58
README.md
58
README.md
@@ -1,6 +1,58 @@
|
|||||||
# SkinRestorer
|
# SkinRestorer
|
||||||
This is a server-side only mod for fabric.
|
|
||||||
|
|
||||||
It allows you to use and change skins on servers that are in offline/insecure mode.
|

|
||||||
|

|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/skinrestorer)
|
||||||
|
[](https://modrinth.com/mod/skinrestorer)
|
||||||
|
|
||||||
After installation on server use /skin command to change skin.
|
SkinRestorer is a **server-side** only mod for Fabric that allows players to use and change skins on servers running in
|
||||||
|
offline/insecure mode.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Set Skins from Mojang Account**: Fetch and apply skins using a valid Minecraft account name.
|
||||||
|
- **Set Skins from URL**: Apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
||||||
|
|
||||||
|
## Command Usage Guide
|
||||||
|
|
||||||
|
### Set Mojang Skin
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin set mojang <username> [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `<username>`: Minecraft account name to fetch the skin from.
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||||
|
|
||||||
|
### Set Web Skin
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin set web (classic|slim) "<url>" [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `(classic|slim)`: Type of the skin model (`classic` for Steve model, `slim` for Alex model).
|
||||||
|
- `"<url>"`: URL pointing to the skin image file (ensure it follows Minecraft's skin size and format requirements).
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||||
|
|
||||||
|
### Clear Skin
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin clear [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to clear the skin for.
|
||||||
|
|
||||||
|
### Notes:
|
||||||
|
|
||||||
|
- If `targets` is not specified, the command will apply to the player executing the command.
|
||||||
|
|
||||||
|
### Examples:
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin set mojang Notch
|
||||||
|
/skin set web classic "https://example.com/skin.png"
|
||||||
|
/skin clear @a
|
||||||
|
```
|
||||||
|
|||||||
87
build.gradle
87
build.gradle
@@ -1,78 +1,13 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.0-SNAPSHOT'
|
// see https://fabricmc.net/develop/ for new versions
|
||||||
id 'maven-publish'
|
id 'fabric-loom' version '1.7-SNAPSHOT' apply false
|
||||||
}
|
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
||||||
|
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
id 'net.minecraftforge.gradle' version '6.0.26' apply false
|
||||||
|
id 'org.parchmentmc.librarian.forgegradle' version '1.+' apply false
|
||||||
archivesBaseName = project.archives_base_name
|
|
||||||
version = project.mod_version
|
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply false
|
||||||
group = project.maven_group
|
|
||||||
|
id 'me.modmuss50.mod-publish-plugin' version '0.6.3' apply false
|
||||||
repositories {
|
|
||||||
// Add repositories to retrieve artifacts from in here.
|
|
||||||
// You should only use this when depending on other mods because
|
|
||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
|
||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
|
||||||
// for more information about repositories.
|
|
||||||
maven { url = "https://masa.dy.fi/maven" }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// To change the versions see the gradle.properties file
|
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
|
||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
|
||||||
|
|
||||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
|
||||||
// You may need to force-disable transitiveness on them.
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
|
||||||
inputs.property "version", project.version
|
|
||||||
|
|
||||||
filesMatching("fabric.mod.json") {
|
|
||||||
expand "version": project.version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
|
||||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
|
||||||
// this fixes some edge cases with special characters not displaying correctly
|
|
||||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
|
||||||
// If Javadoc is generated, this must be specified in that task too.
|
|
||||||
it.options.encoding = "UTF-8"
|
|
||||||
|
|
||||||
it.options.release = 17
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
|
||||||
// if it is present.
|
|
||||||
// If you remove this line, sources will not be generated.
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
|
||||||
from("LICENSE") {
|
|
||||||
rename { "${it}_${project.archivesBaseName}"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure the maven publication
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenJava(MavenPublication) {
|
|
||||||
from components.java
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
|
||||||
repositories {
|
|
||||||
// Add repositories to publish to here.
|
|
||||||
// Notice: This block does NOT have the same function as the block in the top level.
|
|
||||||
// The repositories here will be used for publishing your artifact, not for
|
|
||||||
// retrieving dependencies.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
3
buildSrc/build.gradle
Normal file
3
buildSrc/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
plugins {
|
||||||
|
id 'groovy-gradle-plugin'
|
||||||
|
}
|
||||||
107
buildSrc/src/main/groovy/multiloader-common.gradle
Normal file
107
buildSrc/src/main/groovy/multiloader-common.gradle
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
}
|
||||||
|
|
||||||
|
base {
|
||||||
|
archivesName = "${mod_id}-${project.name}"
|
||||||
|
version = "${mod_version}+${minecraft_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = 'ParchmentMC'
|
||||||
|
url = 'https://maven.parchmentmc.org'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = 'Forge'
|
||||||
|
url = 'https://maven.minecraftforge.net'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = 'NeoForge'
|
||||||
|
url = 'https://maven.neoforged.net/releases'
|
||||||
|
}
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'Sponge'
|
||||||
|
url = 'https://repo.spongepowered.org/repository/maven-public'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('org.spongepowered')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Declare capabilities on the outgoing configurations.
|
||||||
|
// Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component
|
||||||
|
['apiElements', 'runtimeElements', 'sourcesElements'].each { variant ->
|
||||||
|
configurations."$variant".outgoing {
|
||||||
|
capability("$group:${base.archivesName.get()}:$version")
|
||||||
|
capability("$group:$mod_id-${project.name}:$version")
|
||||||
|
capability("$group:$mod_id:$version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcesJar {
|
||||||
|
from(rootProject.file('LICENSE')) {
|
||||||
|
rename { "${it}_${mod_name}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from(rootProject.file('LICENSE')) {
|
||||||
|
rename { "${it}_${mod_name}" }
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes([
|
||||||
|
'Specification-Title' : mod_name,
|
||||||
|
'Specification-Vendor' : mod_author,
|
||||||
|
'Specification-Version' : project.jar.archiveVersion,
|
||||||
|
'Implementation-Title' : project.name,
|
||||||
|
'Implementation-Version': project.jar.archiveVersion,
|
||||||
|
'Implementation-Vendor' : mod_author,
|
||||||
|
'Built-On-Minecraft' : minecraft_version
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
def expandProps = [
|
||||||
|
'version' : version,
|
||||||
|
'group' : project.group, //Else we target the task's group.
|
||||||
|
'minecraft_version' : minecraft_version,
|
||||||
|
'minecraft_version_range' : minecraft_version_range,
|
||||||
|
'fabric_loader_version' : fabric_loader_version,
|
||||||
|
'mod_name' : mod_name,
|
||||||
|
'mod_author' : mod_author,
|
||||||
|
'mod_id' : mod_id,
|
||||||
|
'mod_homepage' : mod_homepage,
|
||||||
|
'mod_sources' : mod_sources,
|
||||||
|
'mod_issues' : mod_issues,
|
||||||
|
'license' : license,
|
||||||
|
'description' : project.description,
|
||||||
|
'forge_version' : forge_version,
|
||||||
|
'forge_loader_version_range' : forge_loader_version_range,
|
||||||
|
'neoforge_version' : neoforge_version,
|
||||||
|
'neoforge_loader_version_range': neoforge_loader_version_range,
|
||||||
|
'credits' : credits,
|
||||||
|
'java_version' : java_version
|
||||||
|
]
|
||||||
|
|
||||||
|
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
||||||
|
expand expandProps
|
||||||
|
}
|
||||||
|
inputs.properties(expandProps)
|
||||||
|
}
|
||||||
39
buildSrc/src/main/groovy/multiloader-loader.gradle
Normal file
39
buildSrc/src/main/groovy/multiloader-loader.gradle
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
plugins {
|
||||||
|
id 'multiloader-common'
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
commonJava{
|
||||||
|
canBeResolved = true
|
||||||
|
}
|
||||||
|
commonResources{
|
||||||
|
canBeResolved = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly(project(':common')) {
|
||||||
|
capabilities {
|
||||||
|
requireCapability "$group:$mod_id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commonJava project(path: ':common', configuration: 'commonJava')
|
||||||
|
commonResources project(path: ':common', configuration: 'commonResources')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('compileJava', JavaCompile) {
|
||||||
|
dependsOn(configurations.commonJava)
|
||||||
|
source(configurations.commonJava)
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
dependsOn(configurations.commonResources)
|
||||||
|
from(configurations.commonResources)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('sourcesJar', Jar) {
|
||||||
|
dependsOn(configurations.commonJava)
|
||||||
|
from(configurations.commonJava)
|
||||||
|
dependsOn(configurations.commonResources)
|
||||||
|
from(configurations.commonResources)
|
||||||
|
}
|
||||||
35
buildSrc/src/main/groovy/multiloader-publish.gradle
Normal file
35
buildSrc/src/main/groovy/multiloader-publish.gradle
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
plugins {
|
||||||
|
id "me.modmuss50.mod-publish-plugin"
|
||||||
|
}
|
||||||
|
|
||||||
|
publishMods {
|
||||||
|
if (project.name == 'fabric')
|
||||||
|
file = remapJar.archiveFile
|
||||||
|
else
|
||||||
|
file = jar.archiveFile
|
||||||
|
|
||||||
|
modLoaders.add(project.name)
|
||||||
|
type = STABLE
|
||||||
|
version = project.version
|
||||||
|
displayName = "[${project.name.capitalize()}] ${mod_name} ${mod_version}"
|
||||||
|
changelog = rootProject.file('CHANGELOG_LATEST.md').text
|
||||||
|
|
||||||
|
curseforge {
|
||||||
|
projectId = curseforge_id
|
||||||
|
|
||||||
|
dryRun = providers.environmentVariable("CURSEFORGE_API_KEY").getOrNull() == null
|
||||||
|
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
|
||||||
|
|
||||||
|
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||||
|
serverRequired = true
|
||||||
|
}
|
||||||
|
|
||||||
|
modrinth {
|
||||||
|
projectId = modrinth_id
|
||||||
|
|
||||||
|
dryRun = providers.environmentVariable("MODRINTH_TOKEN").getOrNull() == null
|
||||||
|
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
|
||||||
|
|
||||||
|
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
41
common/build.gradle
Normal file
41
common/build.gradle
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
plugins {
|
||||||
|
id 'multiloader-common'
|
||||||
|
|
||||||
|
id 'fabric-loom'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||||
|
mappings loom.layered {
|
||||||
|
officialMojangMappings()
|
||||||
|
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||||
|
}
|
||||||
|
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
|
||||||
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
def aw = project.file("src/main/resources/${mod_id}.accesswidener")
|
||||||
|
if (aw.exists()) {
|
||||||
|
accessWidenerPath.set(aw)
|
||||||
|
}
|
||||||
|
|
||||||
|
mixin {
|
||||||
|
useLegacyMixinAp = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
commonJava {
|
||||||
|
canBeResolved = false
|
||||||
|
canBeConsumed = true
|
||||||
|
}
|
||||||
|
commonResources {
|
||||||
|
canBeResolved = false
|
||||||
|
canBeConsumed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
commonJava sourceSets.main.java.sourceDirectories.singleFile
|
||||||
|
commonResources sourceSets.main.resources.sourceDirectories.singleFile
|
||||||
|
}
|
||||||
1
common/gradle.properties
Normal file
1
common/gradle.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
fabric.loom.dontRemap = true
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.*;
|
||||||
|
import net.lionarius.skinrestorer.translation.Translation;
|
||||||
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public final class SkinRestorer {
|
||||||
|
public static final String MOD_ID = "skinrestorer";
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger("SkinRestorer");
|
||||||
|
|
||||||
|
private static final SkinProviderRegistry providersRegistry = new SkinProviderRegistry();
|
||||||
|
private static SkinStorage skinStorage;
|
||||||
|
private static Path configDir;
|
||||||
|
private static Config config;
|
||||||
|
|
||||||
|
private SkinRestorer() {}
|
||||||
|
|
||||||
|
public static SkinStorage getSkinStorage() {
|
||||||
|
return SkinRestorer.skinStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path getConfigDir() {
|
||||||
|
return SkinRestorer.configDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Config getConfig() {
|
||||||
|
return SkinRestorer.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinProviderRegistry getProvidersRegistry() {
|
||||||
|
return SkinRestorer.providersRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<SkinProvider> getProvider(String name) {
|
||||||
|
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onInitialize(Path rootConfigDir) {
|
||||||
|
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
||||||
|
SkinRestorer.reloadConfig();
|
||||||
|
|
||||||
|
SkinRestorer.providersRegistry.register(EmptySkinProvider.PROVIDER_NAME, SkinProvider.EMPTY, false);
|
||||||
|
SkinRestorer.providersRegistry.register(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG);
|
||||||
|
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
||||||
|
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onServerStarted(MinecraftServer server) {
|
||||||
|
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||||
|
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
||||||
|
|
||||||
|
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadConfig() {
|
||||||
|
SkinRestorer.config = Config.load(SkinRestorer.getConfigDir());
|
||||||
|
Translation.reloadTranslations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String resource(String name) {
|
||||||
|
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||||
|
var acceptedPlayers = new HashSet<ServerPlayer>();
|
||||||
|
|
||||||
|
for (var profile : targets) {
|
||||||
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
|
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||||
|
|
||||||
|
if (save)
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
|
|
||||||
|
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||||
|
|
||||||
|
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||||
|
if (player == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PlayerUtils.refreshPlayer(player);
|
||||||
|
acceptedPlayers.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acceptedPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value) {
|
||||||
|
return SkinRestorer.applySkin(server, targets, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||||
|
MinecraftServer server,
|
||||||
|
Collection<GameProfile> targets,
|
||||||
|
SkinProviderContext context,
|
||||||
|
boolean save
|
||||||
|
) {
|
||||||
|
return CompletableFuture.supplyAsync(
|
||||||
|
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.getSkin(context.argument(), context.variant()))
|
||||||
|
)
|
||||||
|
.thenApplyAsync(result -> {
|
||||||
|
if (result.isEmpty())
|
||||||
|
return Result.<Collection<ServerPlayer>, String>error("provider '" + context.name() + "' is not registered");
|
||||||
|
|
||||||
|
var skinResult = result.get();
|
||||||
|
if (skinResult.isError())
|
||||||
|
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
|
||||||
|
|
||||||
|
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
||||||
|
|
||||||
|
var acceptedPlayers = SkinRestorer.applySkin(server, targets, skinValue, save);
|
||||||
|
|
||||||
|
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
|
||||||
|
}, server)
|
||||||
|
.exceptionally(e -> {
|
||||||
|
SkinRestorer.LOGGER.error(e.toString());
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
package net.lionarius.skinrestorer.command;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.SkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
|
import net.lionarius.skinrestorer.translation.Translation;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static net.minecraft.commands.Commands.argument;
|
||||||
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
|
||||||
|
public final class SkinCommand {
|
||||||
|
|
||||||
|
private SkinCommand() {}
|
||||||
|
|
||||||
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> base =
|
||||||
|
literal("skin")
|
||||||
|
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
||||||
|
.then(literal("reset")
|
||||||
|
.executes(context -> resetSubcommand(context.getSource()))
|
||||||
|
.then(makeTargetsArgument(
|
||||||
|
(context, profiles) -> resetSubcommand(context.getSource(), profiles, true)
|
||||||
|
)))
|
||||||
|
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> set = literal("set");
|
||||||
|
|
||||||
|
var providers = SkinRestorer.getProvidersRegistry().getPublicProviders();
|
||||||
|
for (var entry : providers)
|
||||||
|
set.then(buildSetSubcommand(entry.first(), entry.second()));
|
||||||
|
|
||||||
|
base.then(set);
|
||||||
|
|
||||||
|
dispatcher.register(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int refreshSubcommand(
|
||||||
|
CommandSourceStack src
|
||||||
|
) {
|
||||||
|
var player = src.getPlayer();
|
||||||
|
if (player == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var profile = player.getGameProfile();
|
||||||
|
|
||||||
|
SkinProviderContext context = null;
|
||||||
|
var save = true;
|
||||||
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||||
|
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||||
|
save = false;
|
||||||
|
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int resetSubcommand(
|
||||||
|
CommandSourceStack src,
|
||||||
|
Collection<GameProfile> targets,
|
||||||
|
boolean setByOperator
|
||||||
|
) {
|
||||||
|
Collection<ServerPlayer> updatedPlayers = new HashSet<>();
|
||||||
|
for (var profile : targets) {
|
||||||
|
SkinValue skin = null;
|
||||||
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
|
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||||
|
|
||||||
|
if (skin == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||||
|
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||||
|
|
||||||
|
updatedPlayers.addAll(updatedPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SkinCommand.sendResponse(src, updatedPlayers, setByOperator);
|
||||||
|
|
||||||
|
return targets.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int resetSubcommand(
|
||||||
|
CommandSourceStack src
|
||||||
|
) {
|
||||||
|
if (src.getPlayer() == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int setSubcommand(
|
||||||
|
CommandSourceStack src,
|
||||||
|
Collection<GameProfile> targets,
|
||||||
|
SkinProviderContext context,
|
||||||
|
boolean save,
|
||||||
|
boolean setByOperator
|
||||||
|
) {
|
||||||
|
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||||
|
|
||||||
|
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||||
|
if (result.isError()) {
|
||||||
|
src.sendFailure(Translation.translatableWithFallback(
|
||||||
|
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||||
|
result.getErrorValue()
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var updatedPlayers = result.getSuccessValue();
|
||||||
|
|
||||||
|
SkinCommand.sendResponse(src, updatedPlayers, setByOperator);
|
||||||
|
});
|
||||||
|
|
||||||
|
return targets.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int setSubcommand(
|
||||||
|
CommandSourceStack src,
|
||||||
|
Collection<GameProfile> targets,
|
||||||
|
SkinProviderContext context,
|
||||||
|
boolean setByOperator
|
||||||
|
) {
|
||||||
|
return SkinCommand.setSubcommand(src, targets, context, true, setByOperator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int setSubcommand(
|
||||||
|
CommandSourceStack src,
|
||||||
|
SkinProviderContext context
|
||||||
|
) {
|
||||||
|
if (src.getPlayer() == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
|
||||||
|
if (updatedPlayers.isEmpty()) {
|
||||||
|
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||||
|
Translation.COMMAND_SKIN_NO_CHANGES_KEY
|
||||||
|
), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setByOperator) {
|
||||||
|
var playersComponent = PlayerUtils.createPlayerListComponent(updatedPlayers);
|
||||||
|
|
||||||
|
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||||
|
Translation.COMMAND_SKIN_AFFECTED_PLAYERS_KEY,
|
||||||
|
playersComponent
|
||||||
|
), true);
|
||||||
|
} else {
|
||||||
|
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||||
|
Translation.COMMAND_SKIN_OK_KEY
|
||||||
|
), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
||||||
|
LiteralArgumentBuilder<CommandSourceStack> action = literal(name);
|
||||||
|
|
||||||
|
if (provider.hasVariantSupport()) {
|
||||||
|
for (SkinVariant variant : SkinVariant.values()) {
|
||||||
|
action.then(
|
||||||
|
literal(variant.toString())
|
||||||
|
.then(buildSetSubcommandArgument(
|
||||||
|
argument(provider.getArgumentName(), StringArgumentType.string()),
|
||||||
|
context -> {
|
||||||
|
var argument = StringArgumentType.getString(context, provider.getArgumentName());
|
||||||
|
return new SkinProviderContext(name, argument, variant);
|
||||||
|
}
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
action.then(
|
||||||
|
buildSetSubcommandArgument(
|
||||||
|
argument(provider.getArgumentName(), StringArgumentType.string()),
|
||||||
|
context -> {
|
||||||
|
var argument = StringArgumentType.getString(context, provider.getArgumentName());
|
||||||
|
return new SkinProviderContext(name, argument, null);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArgumentBuilder<CommandSourceStack, LiteralArgumentBuilder<CommandSourceStack>> buildSetSubcommand(
|
||||||
|
String name,
|
||||||
|
Supplier<SkinProviderContext> supplier
|
||||||
|
) {
|
||||||
|
return buildSetSubcommandArgument(literal(name), context -> supplier.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends ArgumentBuilder<CommandSourceStack, T>> ArgumentBuilder<CommandSourceStack, T> buildSetSubcommandArgument(
|
||||||
|
ArgumentBuilder<CommandSourceStack, T> argument,
|
||||||
|
Function<CommandContext<CommandSourceStack>, SkinProviderContext> provider
|
||||||
|
) {
|
||||||
|
return argument
|
||||||
|
.executes(context -> setSubcommand(
|
||||||
|
context.getSource(),
|
||||||
|
provider.apply(context)
|
||||||
|
))
|
||||||
|
.then(makeTargetsArgument(
|
||||||
|
(context, targets) -> setSubcommand(
|
||||||
|
context.getSource(),
|
||||||
|
targets,
|
||||||
|
provider.apply(context),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||||
|
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
||||||
|
) {
|
||||||
|
return argument("targets", GameProfileArgument.gameProfile())
|
||||||
|
.requires(source -> source.hasPermission(2))
|
||||||
|
.executes(context -> consumer.apply(context, GameProfileArgument.getGameProfiles(context, "targets")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class Config {
|
||||||
|
|
||||||
|
public static final String CONFIG_FILENAME = "config.json";
|
||||||
|
|
||||||
|
|
||||||
|
private String language = "en_us";
|
||||||
|
|
||||||
|
private boolean fetchSkinOnFirstJoin = true;
|
||||||
|
|
||||||
|
private String proxy = "";
|
||||||
|
|
||||||
|
private long requestTimeout = 10;
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return this.language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean fetchSkinOnFirstJoin() {
|
||||||
|
return this.fetchSkinOnFirstJoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxy() {
|
||||||
|
return this.proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRequestTimeout() {
|
||||||
|
return this.requestTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Config load(Path path) {
|
||||||
|
var configFile = path.resolve(Config.CONFIG_FILENAME);
|
||||||
|
|
||||||
|
Config config = null;
|
||||||
|
try {
|
||||||
|
config = JsonUtils.fromJson(FileUtils.readFile(configFile), Config.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Could not load config", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config == null)
|
||||||
|
config = new Config();
|
||||||
|
|
||||||
|
FileUtils.writeFile(path.resolve(Config.CONFIG_FILENAME), JsonUtils.toJson(config));
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.lionarius.skinrestorer.mixin;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import net.minecraft.server.level.ChunkMap;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(ChunkMap.class)
|
||||||
|
public interface ChunkMapAccessor {
|
||||||
|
|
||||||
|
@Accessor
|
||||||
|
Int2ObjectMap<Object> getEntityMap();
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.lionarius.skinrestorer.mixin;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.CommonListenerCookie;
|
||||||
|
import net.minecraft.server.players.PlayerList;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mixin(PlayerList.class)
|
||||||
|
public abstract class PlayerListMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract List<ServerPlayer> getPlayers();
|
||||||
|
|
||||||
|
@Shadow @Final
|
||||||
|
private MinecraftServer server;
|
||||||
|
|
||||||
|
@Inject(method = "remove", at = @At("TAIL"))
|
||||||
|
private void remove(ServerPlayer player, CallbackInfo ci) {
|
||||||
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "removeAll", at = @At("HEAD"))
|
||||||
|
private void removeAll(CallbackInfo ci) {
|
||||||
|
for (ServerPlayer player : getPlayers()) {
|
||||||
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
|
||||||
|
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
|
||||||
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||||
|
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package net.lionarius.skinrestorer.mixin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Mixin(ServerLoginPacketListenerImpl.class)
|
||||||
|
public abstract class ServerLoginPacketListenerImplMixin {
|
||||||
|
|
||||||
|
@Shadow @Nullable
|
||||||
|
private GameProfile authenticatedProfile;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private CompletableFuture<Void> skinrestorer_pendingSkin;
|
||||||
|
|
||||||
|
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||||
|
cancellable = true)
|
||||||
|
public void waitForSkin(CallbackInfo ci) {
|
||||||
|
if (skinrestorer_pendingSkin == null) {
|
||||||
|
skinrestorer_pendingSkin = CompletableFuture.supplyAsync(() -> {
|
||||||
|
assert authenticatedProfile != null;
|
||||||
|
var originalSkin = PlayerUtils.getPlayerSkin(authenticatedProfile);
|
||||||
|
|
||||||
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(authenticatedProfile.getId())) {
|
||||||
|
if (originalSkin != null) { // update to the latest official skin
|
||||||
|
var value = SkinRestorer.getSkinStorage().getSkin(authenticatedProfile.getId());
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), value.setOriginalValue(originalSkin));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||||
|
SkinRestorer.LOGGER.debug("Fetching {}'s skin", authenticatedProfile.getName());
|
||||||
|
|
||||||
|
var context = new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, authenticatedProfile.getName(), null);
|
||||||
|
var result = SkinRestorer.getProvider(context.name()).map(
|
||||||
|
provider -> provider.getSkin(context.argument(), context.variant())
|
||||||
|
).orElse(Result.ofNullable(null));
|
||||||
|
|
||||||
|
if (!result.isError()) {
|
||||||
|
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), value);
|
||||||
|
} else {
|
||||||
|
SkinRestorer.LOGGER.warn("failed to fetch skin on first join", result.getErrorValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!skinrestorer_pendingSkin.isDone())
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package net.lionarius.skinrestorer.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerConnection;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
||||||
|
public interface TrackedEntityMixin {
|
||||||
|
|
||||||
|
@Accessor
|
||||||
|
Set<ServerPlayerConnection> getSeenBy();
|
||||||
|
|
||||||
|
@Invoker
|
||||||
|
void invokeRemovePlayer(ServerPlayer player);
|
||||||
|
|
||||||
|
@Invoker
|
||||||
|
void invokeUpdatePlayer(ServerPlayer player);
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MineskinSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SkinIO {
|
||||||
|
|
||||||
|
public static final String FILE_EXTENSION = ".json";
|
||||||
|
|
||||||
|
private final Path savePath;
|
||||||
|
|
||||||
|
public SkinIO(Path savePath) {
|
||||||
|
this.savePath = savePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean skinExists(UUID uuid) {
|
||||||
|
return Files.exists(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinValue loadSkin(UUID uuid) {
|
||||||
|
try {
|
||||||
|
var value = SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||||
|
Objects.requireNonNull(value.provider());
|
||||||
|
return value;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return SkinValue.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SkinValue loadSkin(Path file) {
|
||||||
|
var json = FileUtils.readFile(file);
|
||||||
|
try {
|
||||||
|
return JsonUtils.fromJson(json, SkinValue.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
var property = JsonUtils.fromJson(json, Property.class);
|
||||||
|
return SkinIO.convertFromOldFormat(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSkin(UUID uuid, SkinValue skin) {
|
||||||
|
FileUtils.writeFile(savePath.resolve(SkinIO.uuidToFilename(uuid)), JsonUtils.toJson(skin));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteSkin(UUID uuid) {
|
||||||
|
FileUtils.deleteFile(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String uuidToFilename(UUID uuid) {
|
||||||
|
return uuid + FILE_EXTENSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SkinValue convertFromOldFormat(Property property) {
|
||||||
|
try {
|
||||||
|
var propertyJson = Objects.requireNonNull(JsonUtils.skinPropertyToJson(property));
|
||||||
|
var textures = propertyJson.getAsJsonObject("textures");
|
||||||
|
|
||||||
|
var capeTexture = textures.getAsJsonObject("CAPE");
|
||||||
|
if (capeTexture != null) {
|
||||||
|
var profileName = propertyJson.get("profileName").getAsString();
|
||||||
|
return new SkinValue(MojangSkinProvider.PROVIDER_NAME, profileName, null, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
var skinTexture = textures.getAsJsonObject("SKIN");
|
||||||
|
var url = skinTexture.get("url").getAsString();
|
||||||
|
|
||||||
|
var variant = SkinVariant.CLASSIC;
|
||||||
|
var metadata = skinTexture.getAsJsonObject("metadata");
|
||||||
|
if (metadata != null) {
|
||||||
|
var model = metadata.get("model");
|
||||||
|
if (model != null && "slim".equals(model.getAsString()))
|
||||||
|
variant = SkinVariant.SLIM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SkinValue(MineskinSkinProvider.PROVIDER_NAME, url, variant, property);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return SkinValue.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class SkinStorage {
|
||||||
|
|
||||||
|
private final Map<UUID, SkinValue> skinMap = new ConcurrentHashMap<>();
|
||||||
|
private final SkinIO skinIO;
|
||||||
|
|
||||||
|
public SkinStorage(SkinIO skinIO) {
|
||||||
|
this.skinIO = skinIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSavedSkin(UUID uuid) {
|
||||||
|
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinValue getSkin(UUID uuid) {
|
||||||
|
if (!skinMap.containsKey(uuid)) {
|
||||||
|
var skin = skinIO.loadSkin(uuid);
|
||||||
|
setSkin(uuid, skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return skinMap.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSkin(UUID uuid, boolean save) {
|
||||||
|
var skin = skinMap.remove(uuid);
|
||||||
|
if (skin != null && save)
|
||||||
|
skinIO.saveSkin(uuid, skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSkin(UUID uuid) {
|
||||||
|
this.removeSkin(uuid, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteSkin(UUID uuid) {
|
||||||
|
this.removeSkin(uuid, false);
|
||||||
|
this.skinIO.deleteSkin(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkin(UUID uuid, SkinValue skin) {
|
||||||
|
if (skin == null)
|
||||||
|
skin = SkinValue.EMPTY;
|
||||||
|
|
||||||
|
if (skinMap.containsKey(uuid) && skin.originalValue() == null)
|
||||||
|
skin = skin.setOriginalValue(skinMap.get(uuid).originalValue());
|
||||||
|
|
||||||
|
skinMap.put(uuid, skin);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.EmptySkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
|
||||||
|
@Nullable Property value, @Nullable Property originalValue) {
|
||||||
|
|
||||||
|
public static final SkinValue EMPTY = new SkinValue(EmptySkinProvider.PROVIDER_NAME, null, null, null);
|
||||||
|
|
||||||
|
public SkinValue(String provider, String argument, SkinVariant variant, Property value) {
|
||||||
|
this(provider, argument, variant, value, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinValue fromProviderContextWithValue(SkinProviderContext context, Property value) {
|
||||||
|
return new SkinValue(context.name(), context.argument(), context.variant(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinProviderContext toProviderContext() {
|
||||||
|
return new SkinProviderContext(this.provider, this.argument, this.variant);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinValue replaceValueWithOriginal() {
|
||||||
|
return new SkinValue(this.provider, this.argument, this.variant, this.originalValue, this.originalValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinValue setOriginalValue(Property originalValue) {
|
||||||
|
return new SkinValue(this.provider, this.argument, this.variant, this.value, originalValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package net.lionarius.skinrestorer.enums;
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
public enum SkinVariant {
|
public enum SkinVariant {
|
||||||
|
|
||||||
CLASSIC("classic"),
|
CLASSIC("classic"),
|
||||||
SLIM("slim");
|
SLIM("slim");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
SkinVariant(String name) {
|
SkinVariant(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public final class ElyBySkinProvider implements SkinProvider {
|
||||||
|
public static final String PROVIDER_NAME = "ely.by";
|
||||||
|
|
||||||
|
private static final URI API_URI;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
API_URI = new URI("http://skinsystem.ely.by/");
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "username";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||||
|
try {
|
||||||
|
var profile = ElyBySkinProvider.getElyByProfile(username);
|
||||||
|
|
||||||
|
var properties = profile.getAsJsonArray("properties");
|
||||||
|
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||||
|
|
||||||
|
return Result.ofNullable(textures);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject getElyByProfile(String username) throws IOException {
|
||||||
|
var request = HttpRequest.newBuilder()
|
||||||
|
.uri(ElyBySkinProvider.API_URI
|
||||||
|
.resolve("textures/signed/")
|
||||||
|
.resolve(username + "?unsigned=false")
|
||||||
|
)
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var response = WebUtils.executeRequest(request);
|
||||||
|
WebUtils.throwOnClientErrors(response);
|
||||||
|
|
||||||
|
if (response.statusCode() != 200)
|
||||||
|
throw new IllegalArgumentException("no profile with name " + username);
|
||||||
|
|
||||||
|
return JsonUtils.parseJson(response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public final class EmptySkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "empty";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "placeholder";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant) {
|
||||||
|
return this.getSkin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result<Optional<Property>, Exception> getSkin() {
|
||||||
|
return Result.ofNullable(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public final class MineskinSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "web";
|
||||||
|
|
||||||
|
private static final URI API_URI;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
API_URI = new URI("https://api.mineskin.org/");
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "url";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> getSkin(String url, SkinVariant variant) {
|
||||||
|
try {
|
||||||
|
var result = MineskinSkinProvider.uploadToMineskin(url, variant);
|
||||||
|
var texture = result.getAsJsonObject("data").getAsJsonObject("texture");
|
||||||
|
|
||||||
|
return Result.ofNullable(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject uploadToMineskin(String url, SkinVariant variant) throws IOException {
|
||||||
|
var body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
||||||
|
.formatted(variant.toString(), "none", 0, url);
|
||||||
|
|
||||||
|
var request = HttpRequest.newBuilder()
|
||||||
|
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var response = WebUtils.executeRequest(request);
|
||||||
|
WebUtils.throwOnClientErrors(response);
|
||||||
|
|
||||||
|
if (response.statusCode() != 200)
|
||||||
|
throw new IllegalArgumentException("could not get mineskin skin");
|
||||||
|
|
||||||
|
return JsonUtils.parseJson(response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public final class MojangSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "mojang";
|
||||||
|
|
||||||
|
private static final URI API_URI;
|
||||||
|
private static final URI SESSION_SERVER_URI;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
API_URI = new URI("https://api.mojang.com/");
|
||||||
|
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com/");
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
||||||
|
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "username";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||||
|
try {
|
||||||
|
var uuid = MojangSkinProvider.getUuid(username);
|
||||||
|
var profile = MojangSkinProvider.getMojangProfile(uuid);
|
||||||
|
|
||||||
|
var properties = profile.getAsJsonArray("properties");
|
||||||
|
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||||
|
|
||||||
|
return Result.ofNullable(textures);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getUuid(final String name) throws IOException {
|
||||||
|
var request = HttpRequest.newBuilder()
|
||||||
|
.uri(MojangSkinProvider.API_URI
|
||||||
|
.resolve("users/profiles/minecraft/")
|
||||||
|
.resolve(name)
|
||||||
|
)
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var response = WebUtils.executeRequest(request);
|
||||||
|
WebUtils.throwOnClientErrors(response);
|
||||||
|
|
||||||
|
if (response.statusCode() != 200)
|
||||||
|
throw new IllegalArgumentException("no profile with name " + name);
|
||||||
|
|
||||||
|
var profile = JsonUtils.parseJson(response.body());
|
||||||
|
if (profile == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return profile.get("id").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject getMojangProfile(String uuid) throws IOException {
|
||||||
|
var request = HttpRequest.newBuilder()
|
||||||
|
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
||||||
|
.resolve("session/minecraft/profile/")
|
||||||
|
.resolve(uuid + "?unsigned=false")
|
||||||
|
)
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var response = WebUtils.executeRequest(request);
|
||||||
|
WebUtils.throwOnClientErrors(response);
|
||||||
|
|
||||||
|
if (response.statusCode() != 200)
|
||||||
|
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||||
|
|
||||||
|
return JsonUtils.parseJson(response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface SkinProvider {
|
||||||
|
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
||||||
|
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||||
|
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||||
|
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||||
|
|
||||||
|
String getArgumentName();
|
||||||
|
|
||||||
|
boolean hasVariantSupport();
|
||||||
|
|
||||||
|
Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
|
||||||
|
public record SkinProviderContext(String name, String argument, SkinVariant variant) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class SkinProviderRegistry {
|
||||||
|
|
||||||
|
private final Map<String, Entry> registry = new HashMap<>();
|
||||||
|
|
||||||
|
public SkinProvider get(String name) {
|
||||||
|
var entry = this.registry.get(name);
|
||||||
|
if (entry == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return entry.provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Pair<String, SkinProvider>> getProviders() {
|
||||||
|
return this.registry
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(entry -> Pair.of(entry.getKey(), entry.getValue().provider))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Pair<String, SkinProvider>> getPublicProviders() {
|
||||||
|
return this.registry
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(entry -> entry.getValue().isPublic)
|
||||||
|
.map(entry -> Pair.of(entry.getKey(), entry.getValue().provider))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(@NotNull String name, @NotNull SkinProvider provider) {
|
||||||
|
this.register(name, provider, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
||||||
|
if (this.registry.containsKey(name))
|
||||||
|
throw new IllegalArgumentException("Skin provider with name " + name + " is already registered");
|
||||||
|
|
||||||
|
this.registry.put(name, new Entry(provider, isPublic));
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Entry(SkinProvider provider, boolean isPublic) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package net.lionarius.skinrestorer.translation;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class Translation {
|
||||||
|
public static final String LEGACY_TRANSLATION_FILENAME = "translation";
|
||||||
|
|
||||||
|
public static final String COMMAND_SKIN_AFFECTED_PLAYERS_KEY = "skinrestorer.command.skin.affected_players";
|
||||||
|
public static final String COMMAND_SKIN_NO_CHANGES_KEY = "skinrestorer.command.skin.no_changes";
|
||||||
|
public static final String COMMAND_SKIN_FAILED_KEY = "skinrestorer.command.skin.failed";
|
||||||
|
public static final String COMMAND_SKIN_OK_KEY = "skinrestorer.command.skin.ok";
|
||||||
|
public static final String COMMAND_SKIN_LOADING_KEY = "skinrestorer.command.skin.loading";
|
||||||
|
|
||||||
|
private static Map<String, String> translations;
|
||||||
|
private static final Map<String, String> fallback;
|
||||||
|
|
||||||
|
static {
|
||||||
|
fallback = Translation.loadTranslationMap("en_us");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Translation() {}
|
||||||
|
|
||||||
|
public static String get(String key) {
|
||||||
|
var value = translations.get(key);
|
||||||
|
if (value == null)
|
||||||
|
value = fallback.get(key);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MutableComponent translatableWithFallback(String key) {
|
||||||
|
return Component.translatableWithFallback(key, Translation.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MutableComponent translatableWithFallback(String key, Object... args) {
|
||||||
|
return Component.translatableWithFallback(key, Translation.get(key), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reloadTranslations() {
|
||||||
|
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().getLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
||||||
|
var json = FileUtils.readResource(SkinRestorer.resource(String.format("lang/%s.json", lang)));
|
||||||
|
|
||||||
|
var type = new TypeToken<Map<String, String>>() {}.getType();
|
||||||
|
Map<String, String> map = null;
|
||||||
|
try {
|
||||||
|
map = JsonUtils.fromJson(Objects.requireNonNull(json), type);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error("Failed to load translation map", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map == null)
|
||||||
|
return ImmutableMap.<String, String>builder().build();
|
||||||
|
|
||||||
|
return ImmutableMap.copyOf(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||||
|
import net.lionarius.skinrestorer.translation.Translation;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public final class FileUtils {
|
||||||
|
|
||||||
|
private FileUtils() {}
|
||||||
|
|
||||||
|
public static void tryMigrateOldSkinDirectory(Path newDirectory) {
|
||||||
|
try {
|
||||||
|
var configDirectory = SkinRestorer.getConfigDir();
|
||||||
|
try (var stream = Files.list(configDirectory)) {
|
||||||
|
var files = stream.filter(file -> {
|
||||||
|
var name = file.getFileName();
|
||||||
|
return Files.isRegularFile(file)
|
||||||
|
&& !name.startsWith(Translation.LEGACY_TRANSLATION_FILENAME)
|
||||||
|
&& !name.startsWith(Config.CONFIG_FILENAME)
|
||||||
|
&& name.endsWith(SkinIO.FILE_EXTENSION);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
if (!files.isEmpty() && !Files.exists(newDirectory))
|
||||||
|
Files.createDirectories(newDirectory);
|
||||||
|
|
||||||
|
|
||||||
|
for (var file : files)
|
||||||
|
Files.move(file, newDirectory.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error("could not migrate skin directory", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String readResource(String name) {
|
||||||
|
try (var stream = SkinRestorer.class.getResourceAsStream(name)) {
|
||||||
|
if (stream == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try (var reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
||||||
|
return StringUtils.readString(reader);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to read resource", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String readFile(Path file) {
|
||||||
|
try {
|
||||||
|
if (!Files.exists(file))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return Files.readString(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to read file", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeFile(Path file, String content) {
|
||||||
|
try {
|
||||||
|
var parent = file.getParent();
|
||||||
|
if (parent != null)
|
||||||
|
Files.createDirectories(parent);
|
||||||
|
|
||||||
|
if (!Files.exists(file))
|
||||||
|
Files.createFile(file);
|
||||||
|
|
||||||
|
Files.writeString(file, content);
|
||||||
|
} catch (IOException e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to write file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteFile(Path file) {
|
||||||
|
try {
|
||||||
|
if (Files.exists(file))
|
||||||
|
Files.delete(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to delete file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public final class JsonUtils {
|
||||||
|
|
||||||
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
private JsonUtils() {}
|
||||||
|
|
||||||
|
public static <T> T fromJson(String json, Class<T> clazz) {
|
||||||
|
return GSON.fromJson(json, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T fromJson(JsonElement json, Class<T> clazz) {
|
||||||
|
return GSON.fromJson(json, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T fromJson(String json, Type type) {
|
||||||
|
return GSON.fromJson(json, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> String toJson(T obj) {
|
||||||
|
return GSON.toJson(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonObject parseJson(String json) {
|
||||||
|
return JsonParser.parseString(json).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonObject skinPropertyToJson(Property property) {
|
||||||
|
try {
|
||||||
|
JsonObject json = GSON.fromJson(new String(Base64.getDecoder().decode(property.value()), StandardCharsets.UTF_8), JsonObject.class);
|
||||||
|
if (json != null)
|
||||||
|
json.remove("timestamp");
|
||||||
|
|
||||||
|
return json;
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error(e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||||
|
import net.lionarius.skinrestorer.mixin.TrackedEntityMixin;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.protocol.game.*;
|
||||||
|
import net.minecraft.server.level.ChunkMap;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.players.PlayerList;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public final class PlayerUtils {
|
||||||
|
|
||||||
|
public static final String TEXTURES_KEY = "textures";
|
||||||
|
|
||||||
|
private PlayerUtils() {}
|
||||||
|
|
||||||
|
public static Component createPlayerListComponent(Collection<ServerPlayer> players) {
|
||||||
|
var component = Component.empty();
|
||||||
|
int index = 0;
|
||||||
|
for (var player : players) {
|
||||||
|
component.append(Objects.requireNonNull(player.getDisplayName()));
|
||||||
|
index++;
|
||||||
|
if (index < players.size())
|
||||||
|
component.append(", ");
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFakePlayer(ServerPlayer player) {
|
||||||
|
return player.getClass() != ServerPlayer.class; // if the player isn't a server player entity, it must be someone's fake player
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void refreshPlayer(ServerPlayer player) {
|
||||||
|
ServerLevel serverLevel = player.serverLevel();
|
||||||
|
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||||
|
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||||
|
|
||||||
|
playerList.broadcastAll(new ClientboundBundlePacket(
|
||||||
|
List.of(
|
||||||
|
new ClientboundPlayerInfoRemovePacket(List.of(player.getUUID())),
|
||||||
|
ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(Collections.singleton(player))
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
var trackedEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||||
|
if (trackedEntity != null) {
|
||||||
|
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
|
||||||
|
for (var observerConnection : seenBy) {
|
||||||
|
var observer = observerConnection.getPlayer();
|
||||||
|
trackedEntity.invokeRemovePlayer(observer);
|
||||||
|
|
||||||
|
var trackedObserverEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||||
|
if (trackedObserverEntity != null) {
|
||||||
|
trackedObserverEntity.invokeRemovePlayer(player);
|
||||||
|
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||||
|
}
|
||||||
|
trackedEntity.invokeUpdatePlayer(observer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!player.isDeadOrDying()) {
|
||||||
|
player.connection.send(new ClientboundBundlePacket(
|
||||||
|
List.of(
|
||||||
|
new ClientboundRespawnPacket(player.createCommonSpawnInfo(serverLevel), ClientboundRespawnPacket.KEEP_ALL_DATA),
|
||||||
|
new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||||
|
player.connection.send(new ClientboundSetEntityMotionPacket(player));
|
||||||
|
var vehicle = player.getVehicle();
|
||||||
|
if (vehicle != null)
|
||||||
|
player.connection.send(new ClientboundSetPassengersPacket(vehicle));
|
||||||
|
if (!player.getPassengers().isEmpty())
|
||||||
|
player.connection.send(new ClientboundSetPassengersPacket(player));
|
||||||
|
|
||||||
|
player.onUpdateAbilities();
|
||||||
|
player.giveExperiencePoints(0);
|
||||||
|
playerList.sendPlayerPermissionLevel(player);
|
||||||
|
playerList.sendLevelInfo(player, serverLevel);
|
||||||
|
playerList.sendAllPlayerInfo(player);
|
||||||
|
playerList.sendActivePlayerEffects(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendActivePlayerEffects(ServerPlayer player) {
|
||||||
|
for (var effect : player.getActiveEffects()) {
|
||||||
|
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Property getPlayerSkin(GameProfile profile) {
|
||||||
|
return profile.getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||||
|
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||||
|
|
||||||
|
if (skin != null)
|
||||||
|
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||||
|
if (x == y)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (x == null || y == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (x.equals(y))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
JsonObject xJson = JsonUtils.skinPropertyToJson(x);
|
||||||
|
JsonObject yJson = JsonUtils.skinPropertyToJson(y);
|
||||||
|
|
||||||
|
if (xJson == null || yJson == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return xJson.equals(yJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Property findTexturesProperty(JsonArray properties) {
|
||||||
|
Property textures = null;
|
||||||
|
for (var property : properties) {
|
||||||
|
var propertyObject = property.getAsJsonObject();
|
||||||
|
if (propertyObject == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
textures = JsonUtils.fromJson(propertyObject, Property.class);
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textures == null)
|
||||||
|
throw new IllegalStateException("no textures in profile");
|
||||||
|
|
||||||
|
return textures;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Result<S, E> {
|
||||||
|
|
||||||
|
private final S successValue;
|
||||||
|
private final E errorValue;
|
||||||
|
|
||||||
|
private Result(S successValue, E errorValue) {
|
||||||
|
if (successValue == null && errorValue == null)
|
||||||
|
throw new IllegalArgumentException("Cannot create result of null values");
|
||||||
|
|
||||||
|
this.successValue = successValue;
|
||||||
|
this.errorValue = errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public S getSuccessValue() {
|
||||||
|
return successValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public E getErrorValue() {
|
||||||
|
return errorValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return successValue != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isError() {
|
||||||
|
return errorValue != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <N> Result<N, E> map(Function<S, N> mapper) {
|
||||||
|
if (successValue == null)
|
||||||
|
return new Result<>(null, errorValue);
|
||||||
|
|
||||||
|
return new Result<>(mapper.apply(successValue), errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <N> Result<S, N> mapError(Function<E, N> mapper) {
|
||||||
|
if (errorValue == null)
|
||||||
|
return new Result<>(successValue, null);
|
||||||
|
|
||||||
|
return new Result<>(successValue, mapper.apply(errorValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<S> toOptional() {
|
||||||
|
return Optional.ofNullable(successValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Result<?, ?> result = (Result<?, ?>) o;
|
||||||
|
return Objects.equals(successValue, result.successValue) && Objects.equals(errorValue, result.errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(successValue, errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||||
|
return new Result<>(successValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||||
|
return new Result<>(null, errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||||
|
return Result.success(Optional.ofNullable(successValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,15 +3,18 @@ package net.lionarius.skinrestorer.util;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class StringUtils {
|
public final class StringUtils {
|
||||||
|
|
||||||
|
private StringUtils() {}
|
||||||
|
|
||||||
public static String readString(BufferedReader reader) throws IOException {
|
public static String readString(BufferedReader reader) throws IOException {
|
||||||
String inputLine;
|
String inputLine;
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
while ((inputLine = reader.readLine()) != null) {
|
while ((inputLine = reader.readLine()) != null) {
|
||||||
response.append(inputLine);
|
response.append(inputLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.toString();
|
return response.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ProxySelector;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public final class WebUtils {
|
||||||
|
|
||||||
|
private WebUtils() {}
|
||||||
|
|
||||||
|
public static final String USER_AGENT;
|
||||||
|
|
||||||
|
static {
|
||||||
|
USER_AGENT = String.format("SkinRestorer/%d", System.currentTimeMillis() % 65535);
|
||||||
|
|
||||||
|
var builder = HttpClient.newBuilder();
|
||||||
|
var proxy = SkinRestorer.getConfig().getProxy();
|
||||||
|
try {
|
||||||
|
if (proxy != null) {
|
||||||
|
var colonIndex = proxy.lastIndexOf(':');
|
||||||
|
if (colonIndex != -1) {
|
||||||
|
var host = proxy.substring(0, colonIndex);
|
||||||
|
var port = Integer.parseInt(proxy.substring(colonIndex + 1));
|
||||||
|
|
||||||
|
builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(host, port)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to parse proxy", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().getRequestTimeout(), ChronoUnit.SECONDS));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to set request timeout", e);
|
||||||
|
builder.connectTimeout(Duration.of(10, ChronoUnit.SECONDS));
|
||||||
|
}
|
||||||
|
|
||||||
|
HTTP_CLIENT = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final HttpClient HTTP_CLIENT;
|
||||||
|
|
||||||
|
public static HttpResponse<String> executeRequest(HttpRequest request) throws IOException {
|
||||||
|
try {
|
||||||
|
var modifiedRequest = HttpRequest.newBuilder(request, (name, value) -> true)
|
||||||
|
.header("User-Agent", WebUtils.USER_AGENT)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
final var response = WebUtils.HTTP_CLIENT.send(modifiedRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
|
if (response.statusCode() >= 500)
|
||||||
|
throw new IOException("server error " + response.statusCode());
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void throwOnClientErrors(HttpResponse<?> response) {
|
||||||
|
String message = null;
|
||||||
|
switch (response.statusCode()) {
|
||||||
|
case 400:
|
||||||
|
message = "bad request";
|
||||||
|
break;
|
||||||
|
case 401:
|
||||||
|
message = "unauthorized";
|
||||||
|
break;
|
||||||
|
case 403:
|
||||||
|
message = "forbidden";
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
message = "not found";
|
||||||
|
break;
|
||||||
|
case 405:
|
||||||
|
message = "method not allowed";
|
||||||
|
break;
|
||||||
|
case 408:
|
||||||
|
message = "request timeout";
|
||||||
|
break;
|
||||||
|
case 429:
|
||||||
|
message = "too many requests";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message != null)
|
||||||
|
throw new IllegalStateException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
common/src/main/resources/assets/skinrestorer/icon.png
Normal file
BIN
common/src/main/resources/assets/skinrestorer/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Změny skinu použity pro %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Žádné změny skinu",
|
||||||
|
"skinrestorer.command.skin.failed": "Nepodařilo se změnit skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin změněn",
|
||||||
|
"skinrestorer.command.skin.loading": "Načítání skinu..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Skin änderungen für %s angewendet",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Keine Skinänderungen",
|
||||||
|
"skinrestorer.command.skin.failed": "Skin konnte nicht geändert werden: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin geändert",
|
||||||
|
"skinrestorer.command.skin.loading": "Skin wird geladen..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Applied skin changes for %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "No skin changes",
|
||||||
|
"skinrestorer.command.skin.failed": "Failed to change skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin changed",
|
||||||
|
"skinrestorer.command.skin.loading": "Loading skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Cambios de skin aplicados para %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
|
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Cambios de skin aplicados para %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
|
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Cambios de skin aplicados para %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
|
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Na-apply ang pagbabago ng skin para kay %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Walang pagbabago sa skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Nabigo sa pagbabago ng skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Nabago ang skin",
|
||||||
|
"skinrestorer.command.skin.loading": "Naglo-load ng skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Modifications de skin appliquées pour %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin changé",
|
||||||
|
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Modifications de skin appliquées pour %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin changé",
|
||||||
|
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "त्वचा परिवर्तन %s के लिए लागू किए गए",
|
||||||
|
"skinrestorer.command.skin.no_changes": "कोई त्वचा परिवर्तन नहीं",
|
||||||
|
"skinrestorer.command.skin.failed": "त्वचा बदलने में विफल: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "त्वचा बदल दी गई",
|
||||||
|
"skinrestorer.command.skin.loading": "त्वचा लोड हो रही है..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Skin változások alkalmazva: %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Nincsenek skin változások",
|
||||||
|
"skinrestorer.command.skin.failed": "Skin változtatás sikertelen: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin megváltoztatva",
|
||||||
|
"skinrestorer.command.skin.loading": "Skin betöltése..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Perubahan skin diterapkan untuk %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Tidak ada perubahan skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Gagal mengubah skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin diubah",
|
||||||
|
"skinrestorer.command.skin.loading": "Memuat skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Modifiche della skin applicate per %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Nessuna modifica alla skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Impossibile cambiare la skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin cambiata",
|
||||||
|
"skinrestorer.command.skin.loading": "Caricamento della skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Zastosowano zmiany skina dla %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Brak zmian skina",
|
||||||
|
"skinrestorer.command.skin.failed": "Nie udało się zmienić skina: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin zmieniony",
|
||||||
|
"skinrestorer.command.skin.loading": "Ładowanie skina..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Alterações de skin aplicadas para %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||||
|
"skinrestorer.command.skin.loading": "Carregando skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Alterações de skin aplicadas para %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||||
|
"skinrestorer.command.skin.loading": "Carregando skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Применены изменения скина для %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Изменений скина нет",
|
||||||
|
"skinrestorer.command.skin.failed": "Не удалось изменить скин: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Скин изменён",
|
||||||
|
"skinrestorer.command.skin.loading": "Загрузка скина..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "%s için skin değişiklikleri uygulandı",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Skin değişikliği yok",
|
||||||
|
"skinrestorer.command.skin.failed": "Skin değiştirme başarısız: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Skin değiştirildi",
|
||||||
|
"skinrestorer.command.skin.loading": "Skin yükleniyor..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Зміни скіна застосовані для %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Змін скіна немає",
|
||||||
|
"skinrestorer.command.skin.failed": "Не вдалося змінити скіна: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Скін змінено",
|
||||||
|
"skinrestorer.command.skin.loading": "Завантаження скіна..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "Áp dụng thay đổi skin cho %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "Không có thay đổi skin",
|
||||||
|
"skinrestorer.command.skin.failed": "Thay đổi skin thất bại: %s",
|
||||||
|
"skinrestorer.command.skin.ok": "Đã thay đổi skin",
|
||||||
|
"skinrestorer.command.skin.loading": "Đang tải skin..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "应用的皮肤更改 %s",
|
||||||
|
"skinrestorer.command.skin.no_changes": "没有皮肤更改",
|
||||||
|
"skinrestorer.command.skin.failed": "更改皮肤失败:%s",
|
||||||
|
"skinrestorer.command.skin.ok": "皮肤已更改",
|
||||||
|
"skinrestorer.command.skin.loading": "正在加载皮肤..."
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"skinrestorer.command.skin.affected_players": "已變更 %s 的外觀",
|
||||||
|
"skinrestorer.command.skin.no_changes": "沒有外觀變更",
|
||||||
|
"skinrestorer.command.skin.failed": "變更外觀失敗:%s",
|
||||||
|
"skinrestorer.command.skin.ok": "已變更外觀",
|
||||||
|
"skinrestorer.command.skin.loading": "正在載入外觀..."
|
||||||
|
}
|
||||||
6
common/src/main/resources/pack.mcmeta
Normal file
6
common/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"description": "${mod_id}",
|
||||||
|
"pack_format": 8
|
||||||
|
}
|
||||||
|
}
|
||||||
16
common/src/main/resources/skinrestorer.mixins.json
Normal file
16
common/src/main/resources/skinrestorer.mixins.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "net.lionarius.skinrestorer.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"refmap": "${mod_id}.refmap.json",
|
||||||
|
"mixins": [
|
||||||
|
"PlayerListMixin",
|
||||||
|
"ServerLoginPacketListenerImplMixin",
|
||||||
|
"ChunkMapAccessor",
|
||||||
|
"TrackedEntityMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
42
fabric/build.gradle
Normal file
42
fabric/build.gradle
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
plugins {
|
||||||
|
id 'multiloader-loader'
|
||||||
|
|
||||||
|
id 'fabric-loom'
|
||||||
|
|
||||||
|
id 'multiloader-publish'
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||||
|
mappings loom.layered {
|
||||||
|
officialMojangMappings()
|
||||||
|
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||||
|
}
|
||||||
|
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
def aw = project(':common').file("src/main/resources/${mod_id}.accesswidener")
|
||||||
|
if (aw.exists()) {
|
||||||
|
accessWidenerPath.set(aw)
|
||||||
|
}
|
||||||
|
|
||||||
|
mixin {
|
||||||
|
defaultRefmapName.set("${mod_id}.refmap.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
runs {
|
||||||
|
client {
|
||||||
|
client()
|
||||||
|
setConfigName('Fabric Client')
|
||||||
|
ideConfigGenerated(true)
|
||||||
|
runDir('../run/client')
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
server()
|
||||||
|
setConfigName('Fabric Server')
|
||||||
|
ideConfigGenerated(true)
|
||||||
|
runDir('../run/server')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
|
public final class SkinRestorerFabric implements ModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
SkinRestorer.onInitialize(FabricLoader.getInstance().getConfigDir());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric.mixin;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(Commands.class)
|
||||||
|
public abstract class CommandsMixin {
|
||||||
|
|
||||||
|
@Final @Shadow
|
||||||
|
private CommandDispatcher<CommandSourceStack> dispatcher;
|
||||||
|
|
||||||
|
@Inject(method = "<init>", at = @At(value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/commands/AdvancementCommands;register(Lcom/mojang/brigadier/CommandDispatcher;)V"))
|
||||||
|
private void init(Commands.CommandSelection environment, CommandBuildContext commandRegistryAccess, CallbackInfo ci) {
|
||||||
|
SkinCommand.register(dispatcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric.mixin;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(MinecraftServer.class)
|
||||||
|
public abstract class MinecraftServerMixin {
|
||||||
|
|
||||||
|
@Inject(method = "runServer",
|
||||||
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||||
|
private void onServerStarted(CallbackInfo ci) {
|
||||||
|
SkinRestorer.onServerStarted((MinecraftServer) (Object) this);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
fabric/src/main/resources/fabric.mod.json
Normal file
32
fabric/src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "${mod_id}",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "${mod_name}",
|
||||||
|
"description": "${description}",
|
||||||
|
"authors": [
|
||||||
|
"${mod_author}"
|
||||||
|
],
|
||||||
|
"contact": {
|
||||||
|
"homepage": "${mod_homepage}",
|
||||||
|
"sources": "${mod_sources}",
|
||||||
|
"issues": "${mod_issues}"
|
||||||
|
},
|
||||||
|
"icon": "assets/${mod_id}/icon.png",
|
||||||
|
"license": "${license}",
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"net.lionarius.skinrestorer.fabric.SkinRestorerFabric"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"${mod_id}.mixins.json",
|
||||||
|
"${mod_id}.fabric.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=${fabric_loader_version}",
|
||||||
|
"minecraft": ">=${minecraft_version}",
|
||||||
|
"java": ">=${java_version}"
|
||||||
|
}
|
||||||
|
}
|
||||||
14
fabric/src/main/resources/skinrestorer.fabric.mixins.json
Normal file
14
fabric/src/main/resources/skinrestorer.fabric.mixins.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "net.lionarius.skinrestorer.fabric.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"refmap": "${mod_id}.refmap.json",
|
||||||
|
"mixins": [
|
||||||
|
"CommandsMixin",
|
||||||
|
"MinecraftServerMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
78
forge/build.gradle
Normal file
78
forge/build.gradle
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
plugins {
|
||||||
|
id 'multiloader-loader'
|
||||||
|
id 'idea'
|
||||||
|
id 'eclipse'
|
||||||
|
|
||||||
|
id 'net.minecraftforge.gradle'
|
||||||
|
id 'org.parchmentmc.librarian.forgegradle'
|
||||||
|
id 'org.spongepowered.mixin'
|
||||||
|
|
||||||
|
id 'multiloader-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
mixin {
|
||||||
|
add sourceSets.main, "${mod_id}.refmap.json"
|
||||||
|
config "${mod_id}.mixins.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
||||||
|
|
||||||
|
copyIdeResources = true //Calls processResources when in dev
|
||||||
|
|
||||||
|
reobf = false // Forge 1.20.6+ uses official mappings at runtime, so we shouldn't reobf from official to SRG
|
||||||
|
|
||||||
|
// Automatically enable forge AccessTransformers if the file exists
|
||||||
|
// This location is hardcoded in Forge and can not be changed.
|
||||||
|
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
|
||||||
|
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||||
|
if (at.exists()) {
|
||||||
|
accessTransformer = at
|
||||||
|
}
|
||||||
|
|
||||||
|
runs {
|
||||||
|
client {
|
||||||
|
workingDirectory file('../run/client')
|
||||||
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
|
taskName 'Client'
|
||||||
|
mods {
|
||||||
|
modClientRun {
|
||||||
|
source sourceSets.main
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
workingDirectory file('../run/server')
|
||||||
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
|
taskName 'Server'
|
||||||
|
mods {
|
||||||
|
modServerRun {
|
||||||
|
source sourceSets.main
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
||||||
|
|
||||||
|
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
||||||
|
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
||||||
|
}
|
||||||
|
|
||||||
|
// for some reason mixin plugin does not add 'MixinConfigs' to MANIFEST.MF so we do it manually
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes([
|
||||||
|
'MixinConfigs': "${mod_id}.mixins.json"
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.each {
|
||||||
|
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
|
||||||
|
it.output.resourcesDir = dir
|
||||||
|
it.java.destinationDirectory = dir
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
|
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.loading.FMLPaths;
|
||||||
|
|
||||||
|
@Mod(SkinRestorer.MOD_ID)
|
||||||
|
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||||
|
public final class SkinRestorerForge {
|
||||||
|
|
||||||
|
public SkinRestorerForge() {
|
||||||
|
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
||||||
|
|
||||||
|
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onCommandRegister(RegisterCommandsEvent event) {
|
||||||
|
SkinCommand.register(event.getDispatcher());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
|
SkinRestorer.onServerStarted(event.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
27
forge/src/main/resources/META-INF/mods.toml
Normal file
27
forge/src/main/resources/META-INF/mods.toml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
modLoader = "javafml"
|
||||||
|
loaderVersion = "${forge_loader_version_range}"
|
||||||
|
license = "${license}"
|
||||||
|
issueTrackerURL = "${mod_issues}"
|
||||||
|
|
||||||
|
[[mods]]
|
||||||
|
modId = "${mod_id}"
|
||||||
|
version = "${version}"
|
||||||
|
displayName = "${mod_name}"
|
||||||
|
authors = "${mod_author}"
|
||||||
|
logoFile = "assets/${mod_id}/icon.png"
|
||||||
|
displayURL = "${mod_homepage}"
|
||||||
|
description = '''${description}'''
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId = "forge"
|
||||||
|
mandatory = true
|
||||||
|
versionRange = "[${forge_version},)"
|
||||||
|
ordering = "NONE"
|
||||||
|
side = "BOTH"
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId = "minecraft"
|
||||||
|
mandatory = true
|
||||||
|
versionRange = "${minecraft_version_range}"
|
||||||
|
ordering = "NONE"
|
||||||
|
side = "BOTH"
|
||||||
@@ -1,11 +1,46 @@
|
|||||||
# Done to increase the memory available to gradle.
|
# Important Notes:
|
||||||
org.gradle.jvmargs=-Xmx1G
|
# Every field you add must be added to the root build.gradle expandProps map.
|
||||||
# Fabric Properties
|
|
||||||
# check these on https://fabricmc.net/versions.html
|
# Project
|
||||||
minecraft_version=1.20.2
|
group=net.lionarius.skinrestorer
|
||||||
yarn_mappings=1.20.2+build.1
|
java_version=21
|
||||||
loader_version=0.14.22
|
|
||||||
# Mod Properties
|
# Common
|
||||||
mod_version=1.2.4
|
minecraft_version=1.21
|
||||||
maven_group=net.lionarius
|
minecraft_version_list=1.21
|
||||||
archives_base_name=skin-restorer
|
minecraft_version_range=[1.21, 1.22)
|
||||||
|
mod_id=skinrestorer
|
||||||
|
mod_name=SkinRestorer
|
||||||
|
mod_version=2.0.2
|
||||||
|
mod_author=Lionarius
|
||||||
|
mod_homepage=https://www.curseforge.com/minecraft/mc-mods/skinrestorer
|
||||||
|
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||||
|
mod_issues=https://github.com/Suiranoil/SkinRestorer/issues
|
||||||
|
license=MIT
|
||||||
|
credits=
|
||||||
|
description=A server-side mod for managing skins.
|
||||||
|
|
||||||
|
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||||
|
parchment_minecraft=1.21
|
||||||
|
parchment_version=2024.07.28
|
||||||
|
|
||||||
|
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||||
|
fabric_loader_version=0.15.0
|
||||||
|
|
||||||
|
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||||
|
forge_version=51.0.0
|
||||||
|
forge_loader_version_range=[51,)
|
||||||
|
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||||
|
forge_minecraft_version=1.21
|
||||||
|
|
||||||
|
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
||||||
|
neoforge_version=21.0.0-beta
|
||||||
|
neoforge_loader_version_range=[4,)
|
||||||
|
|
||||||
|
# Publishing
|
||||||
|
curseforge_id=443823
|
||||||
|
modrinth_id=ghrZDhGW
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
org.gradle.jvmargs=-Xmx3G
|
||||||
|
org.gradle.daemon=false
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
31
gradlew
vendored
31
gradlew
vendored
@@ -55,7 +55,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -83,10 +83,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -133,10 +131,13 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
@@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
|||||||
20
gradlew.bat
vendored
20
gradlew.bat
vendored
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|||||||
42
neoforge/build.gradle
Normal file
42
neoforge/build.gradle
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
plugins {
|
||||||
|
id 'multiloader-loader'
|
||||||
|
id 'idea'
|
||||||
|
id 'eclipse'
|
||||||
|
|
||||||
|
id 'net.neoforged.gradle.userdev'
|
||||||
|
|
||||||
|
id 'multiloader-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Automatically enable neoforge AccessTransformers if the file exists
|
||||||
|
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||||
|
if (at.exists()) {
|
||||||
|
minecraft.accessTransformers.file(at)
|
||||||
|
}
|
||||||
|
|
||||||
|
subsystems {
|
||||||
|
parchment {
|
||||||
|
minecraftVersion = parchment_minecraft
|
||||||
|
mappingsVersion = parchment_version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runs {
|
||||||
|
configureEach {
|
||||||
|
modSource project.sourceSets.main
|
||||||
|
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||||
|
}
|
||||||
|
|
||||||
|
client {
|
||||||
|
workingDirectory = file('../run/client')
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
programArgument '--nogui'
|
||||||
|
workingDirectory = file('../run/server')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "net.neoforged:neoforge:${neoforge_version}"
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.lionarius.skinrestorer.neoforge;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.fml.loading.FMLPaths;
|
||||||
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
|
|
||||||
|
@Mod(SkinRestorer.MOD_ID)
|
||||||
|
@EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||||
|
public final class SkinRestorerNeoForge {
|
||||||
|
|
||||||
|
public SkinRestorerNeoForge() {
|
||||||
|
NeoForge.EVENT_BUS.register(SkinRestorerNeoForge.class);
|
||||||
|
|
||||||
|
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onCommandRegister(RegisterCommandsEvent event) {
|
||||||
|
SkinCommand.register(event.getDispatcher());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
|
SkinRestorer.onServerStarted(event.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
30
neoforge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
30
neoforge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
modLoader = "javafml"
|
||||||
|
loaderVersion = "${neoforge_loader_version_range}"
|
||||||
|
license = "${license}"
|
||||||
|
issueTrackerURL = "${mod_issues}"
|
||||||
|
|
||||||
|
[[mods]]
|
||||||
|
modId = "${mod_id}"
|
||||||
|
version = "${version}"
|
||||||
|
displayName = "${mod_name}"
|
||||||
|
authors = "${mod_author}"
|
||||||
|
logoFile = "assets/${mod_id}/icon.png"
|
||||||
|
displayURL = "${mod_homepage}"
|
||||||
|
description = "${description}"
|
||||||
|
|
||||||
|
[[mixins]]
|
||||||
|
config = "${mod_id}.mixins.json"
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId = "neoforge"
|
||||||
|
type = "required"
|
||||||
|
versionRange = "[${neoforge_version},)"
|
||||||
|
ordering = "NONE"
|
||||||
|
side = "BOTH"
|
||||||
|
|
||||||
|
[[dependencies.${mod_id}]]
|
||||||
|
modId = "minecraft"
|
||||||
|
type = "required"
|
||||||
|
versionRange = "${minecraft_version_range}"
|
||||||
|
ordering = "NONE"
|
||||||
|
side = "BOTH"
|
||||||
@@ -1,9 +1,74 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
|
||||||
name = 'Fabric'
|
|
||||||
url = 'https://maven.fabricmc.net/'
|
|
||||||
}
|
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
|
mavenCentral()
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('net.fabricmc')
|
||||||
|
includeGroupAndSubgroups('fabric-loom')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'Forge'
|
||||||
|
url = 'https://maven.minecraftforge.net'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('net.minecraftforge')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'NeoForge'
|
||||||
|
url = 'https://maven.neoforged.net/releases'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('net.neoforged')
|
||||||
|
includeGroupAndSubgroups('codechicken')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'Sponge'
|
||||||
|
url = 'https://repo.spongepowered.org/repository/maven-public'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('org.spongepowered')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'ParchmentMC'
|
||||||
|
url = 'https://maven.parchmentmc.org'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('org.parchmentmc')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should match the folder name of the project, or else IDEA may complain (see https://youtrack.jetbrains.com/issue/IDEA-317606)
|
||||||
|
rootProject.name = 'skin-restorer'
|
||||||
|
include('common')
|
||||||
|
include('fabric')
|
||||||
|
include('forge')
|
||||||
|
include('neoforge')
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import net.lionarius.skinrestorer.enums.SkinVariant;
|
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class MineskinSkinProvider {
|
|
||||||
|
|
||||||
private static final String API = "https://api.mineskin.org/generate/url";
|
|
||||||
private static final String USER_AGENT = "SkinRestorer";
|
|
||||||
private static final String TYPE = "application/json";
|
|
||||||
|
|
||||||
public static Property getSkin(String url, SkinVariant variant) {
|
|
||||||
try {
|
|
||||||
String input = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
|
||||||
.formatted(variant.toString(), "none", 1, url);
|
|
||||||
|
|
||||||
JsonObject texture = JsonUtils.parseJson(WebUtils.POSTRequest(new URL(API), USER_AGENT, TYPE, TYPE, input))
|
|
||||||
.getAsJsonObject("data").getAsJsonObject("texture");
|
|
||||||
|
|
||||||
return new Property("textures", texture.get("value").getAsString(), texture.get("signature").getAsString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MojangSkinProvider {
|
|
||||||
|
|
||||||
private static final String API = "https://api.mojang.com/users/profiles/minecraft/";
|
|
||||||
private static final String SESSION_SERVER = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
|
||||||
|
|
||||||
public static Property getSkin(String name) {
|
|
||||||
try {
|
|
||||||
UUID uuid = getUUID(name);
|
|
||||||
JsonObject texture = JsonUtils.parseJson(WebUtils.GETRequest(new URL(SESSION_SERVER + uuid + "?unsigned=false")))
|
|
||||||
.getAsJsonArray("properties").get(0).getAsJsonObject();
|
|
||||||
|
|
||||||
return new Property("textures", texture.get("value").getAsString(), texture.get("signature").getAsString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static UUID getUUID(String name) throws IOException {
|
|
||||||
return UUID.fromString(JsonUtils.parseJson(WebUtils.GETRequest(new URL(API + name))).get("id").getAsString()
|
|
||||||
.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer;
|
|
||||||
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import net.lionarius.skinrestorer.util.FileUtils;
|
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class SkinIO {
|
|
||||||
|
|
||||||
private static final String FILE_EXTENSION = ".json";
|
|
||||||
|
|
||||||
private final Path savePath;
|
|
||||||
|
|
||||||
public SkinIO(Path savePath) {
|
|
||||||
this.savePath = savePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Property loadSkin(UUID uuid) {
|
|
||||||
return JsonUtils.fromJson(FileUtils.readFile(savePath.resolve(uuid + FILE_EXTENSION).toFile()), Property.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveSkin(UUID uuid, Property skin) {
|
|
||||||
FileUtils.writeFile(savePath.toFile(), uuid + FILE_EXTENSION, JsonUtils.toJson(skin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import it.unimi.dsi.fastutil.Pair;
|
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.packet.s2c.play.*;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.world.biome.source.BiomeAccess;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class SkinRestorer implements DedicatedServerModInitializer {
|
|
||||||
|
|
||||||
private static SkinStorage skinStorage;
|
|
||||||
|
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("SkinRestorer");
|
|
||||||
|
|
||||||
public static SkinStorage getSkinStorage() {
|
|
||||||
return skinStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInitializeServer() {
|
|
||||||
skinStorage = new SkinStorage(new SkinIO(FabricLoader.getInstance().getConfigDir().resolve("skinrestorer")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void refreshPlayer(ServerPlayerEntity player) {
|
|
||||||
List<com.mojang.datafixers.util.Pair<EquipmentSlot, ItemStack>> equipment = Lists.newArrayList();
|
|
||||||
for (EquipmentSlot slot : EquipmentSlot.values()) {
|
|
||||||
ItemStack itemStack = player.getEquippedStack(slot);
|
|
||||||
if (!itemStack.isEmpty()) {
|
|
||||||
equipment.add(com.mojang.datafixers.util.Pair.of(slot, itemStack.copy()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ServerPlayerEntity observer : player.server.getPlayerManager().getPlayerList()) {
|
|
||||||
observer.networkHandler.sendPacket(new PlayerRemoveS2CPacket(List.of(player.getUuid())));
|
|
||||||
observer.networkHandler.sendPacket(PlayerListS2CPacket.entryFromPlayer(Collections.singleton(player)));
|
|
||||||
|
|
||||||
if (observer == player)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
observer.networkHandler.sendPacket(new EntitiesDestroyS2CPacket(player.getId()));
|
|
||||||
observer.networkHandler.sendPacket(new EntitySpawnS2CPacket(player));
|
|
||||||
observer.networkHandler.sendPacket(new EntityPositionS2CPacket(player));
|
|
||||||
observer.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(player.getId(), player.getDataTracker().getChangedEntries()));
|
|
||||||
|
|
||||||
if (!equipment.isEmpty())
|
|
||||||
observer.networkHandler.sendPacket(new EntityEquipmentUpdateS2CPacket(player.getId(), equipment));
|
|
||||||
|
|
||||||
if (player.hasVehicle())
|
|
||||||
observer.networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player.getVehicle()));
|
|
||||||
}
|
|
||||||
|
|
||||||
player.networkHandler.sendPacket(new PlayerRespawnS2CPacket(player.createCommonPlayerSpawnInfo(player.getServerWorld()), (byte) 2));
|
|
||||||
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
|
|
||||||
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(player.getInventory().selectedSlot));
|
|
||||||
player.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(player.getId(), player.getDataTracker().getChangedEntries()));
|
|
||||||
|
|
||||||
player.sendAbilitiesUpdate();
|
|
||||||
player.playerScreenHandler.updateToClient();
|
|
||||||
|
|
||||||
player.networkHandler.sendPacket(new ExperienceBarUpdateS2CPacket(player.experienceProgress, player.totalExperience, player.experienceLevel));
|
|
||||||
player.networkHandler.sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel()));
|
|
||||||
|
|
||||||
for (StatusEffectInstance instance : player.getStatusEffects())
|
|
||||||
player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getId(), instance));
|
|
||||||
|
|
||||||
if (player.hasVehicle())
|
|
||||||
player.networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player.getVehicle()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompletableFuture<Pair<Collection<ServerPlayerEntity>, Collection<GameProfile>>> setSkinAsync(MinecraftServer server, Collection<GameProfile> targets, Supplier<Property> skinSupplier) {
|
|
||||||
return CompletableFuture.<Pair<Property, Collection<GameProfile>>>supplyAsync(() -> {
|
|
||||||
HashSet<GameProfile> acceptedProfiles = new HashSet<>();
|
|
||||||
Property skin = skinSupplier.get();
|
|
||||||
if (Objects.isNull(skin)) {
|
|
||||||
SkinRestorer.LOGGER.error("Cannot get the skin for {}", targets.stream().findFirst().orElseThrow());
|
|
||||||
return Pair.of(null, Collections.emptySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GameProfile profile : targets) {
|
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), skin);
|
|
||||||
acceptedProfiles.add(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Pair.of(skin, acceptedProfiles);
|
|
||||||
}).<Pair<Collection<ServerPlayerEntity>, Collection<GameProfile>>>thenApplyAsync(pair -> {
|
|
||||||
Property skin = pair.left();
|
|
||||||
if (Objects.isNull(skin))
|
|
||||||
return Pair.of(Collections.emptySet(), Collections.emptySet());
|
|
||||||
|
|
||||||
Collection<GameProfile> acceptedProfiles = pair.right();
|
|
||||||
HashSet<ServerPlayerEntity> acceptedPlayers = new HashSet<>();
|
|
||||||
JsonObject newSkinJson = gson.fromJson(new String(Base64.getDecoder().decode(skin.value()), StandardCharsets.UTF_8), JsonObject.class);
|
|
||||||
newSkinJson.remove("timestamp");
|
|
||||||
for (GameProfile profile : acceptedProfiles) {
|
|
||||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(profile.getId());
|
|
||||||
|
|
||||||
if (player == null || arePropertiesEquals(newSkinJson, player.getGameProfile()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
applyRestoredSkin(player.getGameProfile(), skin);
|
|
||||||
refreshPlayer(player);
|
|
||||||
acceptedPlayers.add(player);
|
|
||||||
}
|
|
||||||
return Pair.of(acceptedPlayers, acceptedProfiles);
|
|
||||||
}, server).orTimeout(10, TimeUnit.SECONDS).exceptionally(e -> Pair.of(Collections.emptySet(), Collections.emptySet()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
|
||||||
profile.getProperties().removeAll("textures");
|
|
||||||
profile.getProperties().put("textures", skin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
|
||||||
private static boolean arePropertiesEquals(@NotNull JsonObject x, @NotNull GameProfile y) {
|
|
||||||
Property py = y.getProperties().get("textures").stream().findFirst().orElse(null);
|
|
||||||
if (py == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
JsonObject jy = gson.fromJson(new String(Base64.getDecoder().decode(py.value()), StandardCharsets.UTF_8), JsonObject.class);
|
|
||||||
jy.remove("timestamp");
|
|
||||||
return x.equals(jy);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SkinRestorer.LOGGER.info("Can not compare skin", ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer;
|
|
||||||
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class SkinStorage {
|
|
||||||
|
|
||||||
public static final Property DEFAULT_SKIN = new Property("textures", "ewogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJpZCIgOiAiZWZhMTFjN2U1YThlNGIwM2JjMDQ0MWRmNzk1YjE0YjIiLAogICAgICAidHlwZSIgOiAiU0tJTiIsCiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTYzNDM4OTUzYTc4MmRhNzY5NDgwYjBhNDkxMjVhOTJlMjU5MjA3NzAwY2I4ZTNlMWFhYzM4ZTQ3MWUyMDMwOCIsCiAgICAgICJwcm9maWxlSWQiIDogImZkNjBmMzZmNTg2MTRmMTJiM2NkNDdjMmQ4NTUyOTlhIiwKICAgICAgInRleHR1cmVJZCIgOiAiOTYzNDM4OTUzYTc4MmRhNzY5NDgwYjBhNDkxMjVhOTJlMjU5MjA3NzAwY2I4ZTNlMWFhYzM4ZTQ3MWUyMDMwOCIKICAgIH0KICB9LAogICJza2luIiA6IHsKICAgICJpZCIgOiAiZWZhMTFjN2U1YThlNGIwM2JjMDQ0MWRmNzk1YjE0YjIiLAogICAgInR5cGUiIDogIlNLSU4iLAogICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS85NjM0Mzg5NTNhNzgyZGE3Njk0ODBiMGE0OTEyNWE5MmUyNTkyMDc3MDBjYjhlM2UxYWFjMzhlNDcxZTIwMzA4IiwKICAgICJwcm9maWxlSWQiIDogImZkNjBmMzZmNTg2MTRmMTJiM2NkNDdjMmQ4NTUyOTlhIiwKICAgICJ0ZXh0dXJlSWQiIDogIjk2MzQzODk1M2E3ODJkYTc2OTQ4MGIwYTQ5MTI1YTkyZTI1OTIwNzcwMGNiOGUzZTFhYWMzOGU0NzFlMjAzMDgiCiAgfSwKICAiY2FwZSIgOiBudWxsCn0=",
|
|
||||||
"T6Czh1iATQTwG/ppZyY9N7cNASVHfGkiicrFykYAve4C7vG36ql0EPf6gMfMIS2eL0FdGLznnWiEC2dUxwNCJwiEyzTo/chlxZMk4TSzkBdBU3KTUZdNZrS/YhTzhi7C4eUVaEtXMRlCVtLQUa8Nb18SFYz243C9tlDsONNk42+xHPN1vRCRGIxfJbcU/mk4/XZzS4zHwPCkB6N4dKX2F6LA+a2P+CUMBluXKF56UiT1j7DjWs8B+6ES0kkmZUGkRaxTtcyN2Rqpx/2wCroohxkyVRAdlkcnwbEHOEKGoYMKdjUWpSm8QrsLkUiyLL3IK/hgd5ET2nI/aE1AloAwr1fotmvf9KF1JIfZljoefYZIaYZ1PpvduwIkAaeeIC4FFcdcBIheHitYyXOBAr/t5E+pTzCJOttDfYggFSyGxOj5yxgXTT4gSwTKp5zkQqiCKdAQQPmgFqxhWkZ2UaE9zq+E5jSOD0OJj3FmBscdZWKoOm+mWZkXbw9z2ZvuqXAKHsi6uVJyGeUzt2hJL8eqOyAmfYsJgfxhGZen5oOlxZra8OxIYlp8TcTwzEIDievgp0dfsGPObGVgtA8D39QiwLXs6e/o0qnzl3+wQJDa/ZqDMISULkBNhPx/TvhYW5MJw3hZIj2gsbf73n+jId1GOUfTVMaFlVf7pvPNqW0PieY=");
|
|
||||||
|
|
||||||
private final Map<UUID, Property> skinMap = new HashMap<>();
|
|
||||||
private final SkinIO skinIO;
|
|
||||||
|
|
||||||
public SkinStorage(SkinIO skinIO) {
|
|
||||||
this.skinIO = skinIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Property getSkin(UUID uuid) {
|
|
||||||
if (!skinMap.containsKey(uuid)) {
|
|
||||||
Property skin = skinIO.loadSkin(uuid);
|
|
||||||
setSkin(uuid, skin);
|
|
||||||
}
|
|
||||||
|
|
||||||
return skinMap.get(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeSkin(UUID uuid) {
|
|
||||||
if (skinMap.containsKey(uuid)) {
|
|
||||||
skinIO.saveSkin(uuid, skinMap.get(uuid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSkin(UUID uuid, Property skin) {
|
|
||||||
if (skin == null)
|
|
||||||
skin = DEFAULT_SKIN;
|
|
||||||
|
|
||||||
skinMap.put(uuid, skin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.command;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
||||||
import net.lionarius.skinrestorer.MineskinSkinProvider;
|
|
||||||
import net.lionarius.skinrestorer.MojangSkinProvider;
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
import net.lionarius.skinrestorer.enums.SkinVariant;
|
|
||||||
import net.lionarius.skinrestorer.util.TranslationUtils;
|
|
||||||
import net.minecraft.command.argument.GameProfileArgumentType;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static net.lionarius.skinrestorer.SkinStorage.DEFAULT_SKIN;
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
|
||||||
|
|
||||||
public class SkinCommand {
|
|
||||||
|
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
||||||
dispatcher.register(literal("skin")
|
|
||||||
.then(literal("set")
|
|
||||||
.then(literal("mojang")
|
|
||||||
.then(argument("skin_name", StringArgumentType.word())
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(),
|
|
||||||
() -> MojangSkinProvider.getSkin(StringArgumentType.getString(context, "skin_name"))))
|
|
||||||
.then(argument("targets", GameProfileArgumentType.gameProfile()).requires(source -> source.hasPermissionLevel(3))
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets"), true,
|
|
||||||
() -> MojangSkinProvider.getSkin(StringArgumentType.getString(context, "skin_name")))))))
|
|
||||||
.then(literal("web")
|
|
||||||
.then(literal("classic")
|
|
||||||
.then(argument("url", StringArgumentType.string())
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(),
|
|
||||||
() -> MineskinSkinProvider.getSkin(StringArgumentType.getString(context, "url"), SkinVariant.CLASSIC)))
|
|
||||||
.then(argument("targets", GameProfileArgumentType.gameProfile()).requires(source -> source.hasPermissionLevel(3))
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets"), true,
|
|
||||||
() -> MineskinSkinProvider.getSkin(StringArgumentType.getString(context, "url"), SkinVariant.CLASSIC))))))
|
|
||||||
.then(literal("slim")
|
|
||||||
.then(argument("url", StringArgumentType.string())
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(),
|
|
||||||
() -> MineskinSkinProvider.getSkin(StringArgumentType.getString(context, "url"), SkinVariant.SLIM)))
|
|
||||||
.then(argument("targets", GameProfileArgumentType.gameProfile()).requires(source -> source.hasPermissionLevel(3))
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets"), true,
|
|
||||||
() -> MineskinSkinProvider.getSkin(StringArgumentType.getString(context, "url"), SkinVariant.SLIM))))))))
|
|
||||||
.then(literal("clear")
|
|
||||||
.executes(context ->
|
|
||||||
skinAction(context.getSource(),
|
|
||||||
() -> DEFAULT_SKIN))
|
|
||||||
.then(argument("targets", GameProfileArgumentType.gameProfile()).executes(context ->
|
|
||||||
skinAction(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets"), true,
|
|
||||||
() -> DEFAULT_SKIN))))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int skinAction(ServerCommandSource src, Collection<GameProfile> targets, boolean setByOperator, Supplier<Property> skinSupplier) {
|
|
||||||
SkinRestorer.setSkinAsync(src.getServer(), targets, skinSupplier).thenAccept(pair -> {
|
|
||||||
Collection<GameProfile> profiles = pair.right();
|
|
||||||
Collection<ServerPlayerEntity> players = pair.left();
|
|
||||||
if (profiles.size() == 0) {
|
|
||||||
src.sendError(Text.of(TranslationUtils.translation.skinActionFailed));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (setByOperator) {
|
|
||||||
src.sendFeedback(() -> Text.of(
|
|
||||||
String.format(TranslationUtils.translation.skinActionAffectedProfile,
|
|
||||||
String.join(", ", profiles.stream().map(GameProfile::getName).toList()))), true);
|
|
||||||
if (players.size() != 0) {
|
|
||||||
src.sendFeedback(() -> Text.of(
|
|
||||||
String.format(TranslationUtils.translation.skinActionAffectedPlayer,
|
|
||||||
String.join(", ", players.stream().map(p -> p.getGameProfile().getName()).toList()))), true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
src.sendFeedback(() -> Text.of(TranslationUtils.translation.skinActionOk), true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return targets.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int skinAction(ServerCommandSource src, Supplier<Property> skinSupplier) {
|
|
||||||
if (src.getPlayer() == null)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return skinAction(src, Collections.singleton(src.getPlayer().getGameProfile()), false, skinSupplier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.mixin;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
|
||||||
import net.minecraft.server.command.CommandManager;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(CommandManager.class)
|
|
||||||
public abstract class CommandManagerMixin {
|
|
||||||
|
|
||||||
@Final
|
|
||||||
@Shadow
|
|
||||||
private CommandDispatcher<ServerCommandSource> dispatcher;
|
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At(value = "TAIL"))
|
|
||||||
private void init(CommandManager.RegistrationEnvironment environment, CommandRegistryAccess commandRegistryAccess, CallbackInfo ci) {
|
|
||||||
SkinCommand.register(dispatcher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.mixin;
|
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
import net.minecraft.network.ClientConnection;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.PlayerManager;
|
|
||||||
import net.minecraft.server.network.ConnectedClientData;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(PlayerManager.class)
|
|
||||||
public abstract class PlayerManagerMixin {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
public abstract List<ServerPlayerEntity> getPlayerList();
|
|
||||||
|
|
||||||
@Shadow @Final private MinecraftServer server;
|
|
||||||
|
|
||||||
@Inject(method = "remove", at = @At("TAIL"))
|
|
||||||
private void remove(ServerPlayerEntity player, CallbackInfo ci) {
|
|
||||||
SkinRestorer.getSkinStorage().removeSkin(player.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "disconnectAllPlayers", at = @At("HEAD"))
|
|
||||||
private void disconnectAllPlayers(CallbackInfo ci) {
|
|
||||||
for (ServerPlayerEntity player : getPlayerList()) {
|
|
||||||
SkinRestorer.getSkinStorage().removeSkin(player.getUuid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "onPlayerConnect", at = @At("HEAD"))
|
|
||||||
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
|
||||||
if (player.getClass() != ServerPlayerEntity.class) // if the player isn't a server player entity, it must be someone's fake player
|
|
||||||
SkinRestorer.setSkinAsync(server, Collections.singleton(player.getGameProfile()), () -> SkinRestorer.getSkinStorage().getSkin(player.getUuid()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.mixin;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import net.lionarius.skinrestorer.MojangSkinProvider;
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
import net.lionarius.skinrestorer.SkinStorage;
|
|
||||||
import net.minecraft.server.network.ServerLoginNetworkHandler;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Mixin(ServerLoginNetworkHandler.class)
|
|
||||||
public abstract class ServerLoginNetworkHandlerMixin {
|
|
||||||
|
|
||||||
@Shadow @Nullable GameProfile profile;
|
|
||||||
|
|
||||||
@Shadow @Final
|
|
||||||
static Logger LOGGER;
|
|
||||||
private CompletableFuture<Property> skinrestorer_pendingSkin;
|
|
||||||
|
|
||||||
@Inject(method = "tickVerify", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;"), cancellable = true)
|
|
||||||
public void waitForSkin(CallbackInfo ci) {
|
|
||||||
if (skinrestorer_pendingSkin == null) {
|
|
||||||
skinrestorer_pendingSkin = CompletableFuture.supplyAsync(() -> {
|
|
||||||
LOGGER.debug("Fetching {}'s skin", profile.getName());
|
|
||||||
if (SkinRestorer.getSkinStorage().getSkin(profile.getId()) == SkinStorage.DEFAULT_SKIN)
|
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), MojangSkinProvider.getSkin(profile.getName()));
|
|
||||||
|
|
||||||
return SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!skinrestorer_pendingSkin.isDone()) {
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "sendSuccessPacket", at = @At("HEAD"))
|
|
||||||
public void applyRestoredSkinHook(GameProfile profile, CallbackInfo ci) {
|
|
||||||
if (skinrestorer_pendingSkin != null)
|
|
||||||
SkinRestorer.applyRestoredSkin(profile, skinrestorer_pendingSkin.getNow(SkinStorage.DEFAULT_SKIN));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class FileUtils {
|
|
||||||
|
|
||||||
public static String readFile(File file) {
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) {
|
|
||||||
return StringUtils.readString(reader);
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean writeFile(File path, String fileName, String content) {
|
|
||||||
try {
|
|
||||||
if (!path.exists())
|
|
||||||
path.mkdirs();
|
|
||||||
|
|
||||||
File file = new File(path, fileName);
|
|
||||||
if (!file.exists())
|
|
||||||
file.createNewFile();
|
|
||||||
|
|
||||||
try (FileWriter writer = new FileWriter(file, StandardCharsets.UTF_8)) {
|
|
||||||
writer.write(content);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
public class JsonUtils {
|
|
||||||
|
|
||||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
|
|
||||||
public static <T> T fromJson(String json, Class<T> clazz) {
|
|
||||||
return GSON.fromJson(json, clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toJson(Object obj) {
|
|
||||||
return GSON.toJson(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonObject parseJson(String json) {
|
|
||||||
return JsonParser.parseString(json).getAsJsonObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class TranslationUtils {
|
|
||||||
public static class Translation {
|
|
||||||
public String skinActionAffectedProfile = "Skin has been saved for %s";
|
|
||||||
public String skinActionAffectedPlayer = "Apply live skin changes for %s";
|
|
||||||
public String skinActionFailed = "Failed to set skin";
|
|
||||||
public String skinActionOk = "Skin changed";
|
|
||||||
}
|
|
||||||
public static Translation translation = new Translation();
|
|
||||||
static {
|
|
||||||
Path path = FabricLoader.getInstance().getConfigDir().resolve("skinrestorer").resolve("translation.json");
|
|
||||||
if (Files.exists(path)) {
|
|
||||||
try {
|
|
||||||
translation = JsonUtils.fromJson(Objects.requireNonNull(FileUtils.readFile(path.toFile())), Translation.class);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SkinRestorer.LOGGER.error("Failed to load translation", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class WebUtils {
|
|
||||||
|
|
||||||
public static String POSTRequest(URL url, String userAgent, String contentType, String responseType, String input) throws IOException {
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type", contentType);
|
|
||||||
connection.setRequestProperty("Accept", responseType);
|
|
||||||
connection.setRequestProperty("User-Agent", userAgent);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setDoInput(true);
|
|
||||||
|
|
||||||
try (OutputStream os = connection.getOutputStream()) {
|
|
||||||
os.write(input.getBytes(StandardCharsets.UTF_8), 0, input.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
|
||||||
return StringUtils.readString(br);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GETRequest(URL url) throws IOException {
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
|
||||||
return StringUtils.readString(br);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"schemaVersion": 1,
|
|
||||||
"id": "skinrestorer",
|
|
||||||
"version": "${version}",
|
|
||||||
|
|
||||||
"name": "Skin Restorer",
|
|
||||||
"description": "",
|
|
||||||
"authors": [
|
|
||||||
"Lionarius"
|
|
||||||
],
|
|
||||||
"contact": {},
|
|
||||||
|
|
||||||
"license": "MIT",
|
|
||||||
|
|
||||||
"environment": "server",
|
|
||||||
"entrypoints": {
|
|
||||||
"server": [
|
|
||||||
"net.lionarius.skinrestorer.SkinRestorer"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"mixins": [
|
|
||||||
"skinrestorer.mixins.json"
|
|
||||||
],
|
|
||||||
|
|
||||||
"depends": {
|
|
||||||
"fabricloader": ">=0.11.3",
|
|
||||||
"minecraft": "*",
|
|
||||||
"java": ">=17"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"required": true,
|
|
||||||
"minVersion": "0.8",
|
|
||||||
"package": "net.lionarius.skinrestorer.mixin",
|
|
||||||
"compatibilityLevel": "JAVA_17",
|
|
||||||
"mixins": [
|
|
||||||
"CommandManagerMixin",
|
|
||||||
"PlayerManagerMixin",
|
|
||||||
"ServerLoginNetworkHandlerMixin"
|
|
||||||
],
|
|
||||||
"injectors": {
|
|
||||||
"defaultRequire": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user