mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
85 Commits
v1.2.6+1.2
...
v2.0.0+1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
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
|
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
|
||||
44
.github/workflows/build.yml
vendored
44
.github/workflows/build.yml
vendored
@@ -1,33 +1,31 @@
|
||||
name: build
|
||||
on: [pull_request, push]
|
||||
on: [ pull_request, push ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
java: [
|
||||
21,
|
||||
]
|
||||
os: [ubuntu-22.04]
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: validate gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
- name: setup jdk ${{ matrix.java }}
|
||||
uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'microsoft'
|
||||
- name: make gradle wrapper executable
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
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: build
|
||||
|
||||
- name: Run build with Gradle Wrapper
|
||||
run: ./gradlew build
|
||||
- name: capture build artifacts
|
||||
if: ${{ runner.os == 'Linux' && matrix.java == '21' }}
|
||||
|
||||
- name: Upload built JAR
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Artifacts
|
||||
path: build/libs/
|
||||
name: skin-restorer-artifacts
|
||||
path: build/libs/merged
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -28,6 +28,5 @@ bin/
|
||||
|
||||
*.DS_Store
|
||||
|
||||
# fabric
|
||||
|
||||
.architectury-transformer/
|
||||
run/
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 LionariusPy
|
||||
Copyright (c) 2021-2024 Lionarius
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
35
README.md
35
README.md
@@ -1,49 +1,58 @@
|
||||
# SkinRestorer
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
[](https://www.curseforge.com/minecraft/mc-mods/skinrestorer)
|
||||
[](https://modrinth.com/mod/skinrestorer)
|
||||
[](https://modrinth.com/mod/skinrestorer)
|
||||
|
||||
|
||||
SkinRestorer is a **server-side** only mod for Fabric that allows players to use and change skins on servers running in offline/insecure mode.
|
||||
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 <skin_name> [<targets>]
|
||||
/skin set mojang <username> [<targets>]
|
||||
```
|
||||
|
||||
- **Parameters:**
|
||||
- `<skin_name>`: Minecraft account name to fetch the skin from.
|
||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||
- `<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.
|
||||
- `(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.
|
||||
- `[<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 "http://example.com/skin.png"
|
||||
/skin set web classic "https://example.com/skin.png"
|
||||
/skin clear @a
|
||||
```
|
||||
|
||||
156
build.gradle
156
build.gradle
@@ -1,41 +1,149 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.7-SNAPSHOT'
|
||||
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "com.github.johnrengelman.shadow" version "8.1.1" apply false
|
||||
id "io.github.pacifistmc.forgix" version "1.2.9"
|
||||
id "me.shedaniel.unified-publishing" version "0.1.+"
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = "${project.mod_version}+${project.minecraft_version}"
|
||||
group = project.maven_group
|
||||
ext.version_name = "${project.capitalized_name} ${project.mod_version}"
|
||||
ext.headTag = "git describe --tags --abbrev=0 HEAD".execute([], rootProject.projectDir).text.trim()
|
||||
ext.previousTag = "git describe --tags --abbrev=0 HEAD^".execute([], rootProject.projectDir).text.trim()
|
||||
|
||||
repositories {
|
||||
maven { url = "https://masa.dy.fi/maven" }
|
||||
architectury {
|
||||
minecraft = project.minecraft_version
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
forgix {
|
||||
group = "$project.maven_group.$project.mod_id"
|
||||
// forgix does not append .jar extension for some reason
|
||||
mergedJarName = "${project.archives_name}-${project.version}.jar"
|
||||
outputDir = "build/libs/merged"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
allprojects {
|
||||
apply plugin: "java"
|
||||
|
||||
version = rootProject.version
|
||||
group = project.maven_group
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
subprojects {
|
||||
apply plugin: "dev.architectury.loom"
|
||||
apply plugin: "architectury-plugin"
|
||||
|
||||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
}
|
||||
|
||||
it.options.release.set(21)
|
||||
base {
|
||||
archivesName = "$rootProject.archives_name-$project.name"
|
||||
}
|
||||
|
||||
build.finalizedBy(mergeJars)
|
||||
assemble.finalizedBy(mergeJars)
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "ParchmentMC"
|
||||
url = "https://maven.parchmentmc.org"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
|
||||
mappings loom.layered {
|
||||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-$rootProject.minecraft_version:$rootProject.parchment_mappings@zip")
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
jar {
|
||||
from "$rootProject.projectDir/LICENSE"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
|
||||
it.options.release.set(21)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
// Adapted from https://raw.githubusercontent.com/TerraformersMC/GradleScripts/2.7/ferry.gradle
|
||||
tasks.register("generateChangelog") {
|
||||
ext.changelog = ""
|
||||
|
||||
def lastTag = previousTag
|
||||
def currentTag = headTag
|
||||
|
||||
def changes = new StringBuilder()
|
||||
def commits = "git log --max-count=${project.changelog_max_commit_search} --pretty=format:\"%b\" $lastTag..$currentTag".execute()
|
||||
commits.in.eachLine { line -> // Loops over the lines the git log command returns
|
||||
def processedLine = line.toString()
|
||||
if (processedLine.startsWith("\"")) {
|
||||
processedLine = processedLine.substring(1)
|
||||
}
|
||||
if (processedLine.endsWith("\"")) {
|
||||
processedLine = processedLine.substring(0, processedLine.length() - 1)
|
||||
}
|
||||
if (processedLine.startsWith("- ")) {
|
||||
if (changes.length() == 0) {
|
||||
changes << processedLine
|
||||
} else {
|
||||
changes << "\n$processedLine"
|
||||
}
|
||||
}
|
||||
}
|
||||
commits.err.eachLine { line -> println line }
|
||||
commits.waitFor()
|
||||
|
||||
ext.changelog = changes.toString()
|
||||
if (ext.changelog.isEmpty()) {
|
||||
ext.changelog = "No Changelog Available"
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
tasks.register("assertNewVersion") {
|
||||
if (headTag == previousTag) {
|
||||
throw new GradleException("Current version $headTag is the same as previous. Please create a new version tag if you want to proceed.")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.publishUnified.dependsOn("assertNewVersion", "build")
|
||||
|
||||
unifiedPublishing {
|
||||
project {
|
||||
displayName = version_name.toString()
|
||||
version = project.version
|
||||
changelog = generateChangelog.changelog
|
||||
releaseType = "release"
|
||||
gameVersions = List.of(project.game_versions.split(","))
|
||||
gameLoaders = List.of(project.mod_loaders.split(","))
|
||||
|
||||
mainPublication.set(file("build/libs/merged/${project.archives_name}-${project.version}.jar"))
|
||||
|
||||
var cfToken = System.getenv("CF_TOKEN")
|
||||
if (cfToken != null) {
|
||||
curseforge {
|
||||
token = cfToken
|
||||
id = project.curseforge_id
|
||||
}
|
||||
}
|
||||
|
||||
var mrToken = System.getenv("MODRINTH_TOKEN")
|
||||
if (mrToken != null) {
|
||||
modrinth {
|
||||
token = mrToken
|
||||
id = project.modrinth_id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
common/build.gradle
Normal file
10
common/build.gradle
Normal file
@@ -0,0 +1,10 @@
|
||||
architectury {
|
||||
common rootProject.enabled_platforms.split(",")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// We depend on Fabric Loader here to use the Fabric @Environment annotations,
|
||||
// which get remapped to the correct annotations on each platform.
|
||||
// Do NOT use other classes from Fabric Loader.
|
||||
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
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;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.translation.Translation;
|
||||
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,75 @@
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
@Shadow @Final
|
||||
MinecraftServer server;
|
||||
|
||||
@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.error("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 {
|
||||
|
||||
|
||||
CLASSIC("classic"),
|
||||
SLIM("slim");
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
SkinVariant(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
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,145 @@
|
||||
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.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
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) {
|
||||
for (var observerConnection : trackedEntity.getSeenBy()) {
|
||||
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 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.IOException;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {}
|
||||
|
||||
public static String readString(BufferedReader reader) throws IOException {
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
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 {
|
||||
var date = new Date();
|
||||
USER_AGENT = String.format("SkinRestorer/%d", date.getTime() % 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": "正在加载皮肤..."
|
||||
}
|
||||
15
common/src/main/resources/skinrestorer-common.mixins.json
Normal file
15
common/src/main/resources/skinrestorer-common.mixins.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.lionarius.skinrestorer.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"ChunkMapAccessor",
|
||||
"TrackedEntityMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
49
fabric/build.gradle
Normal file
49
fabric/build.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow"
|
||||
}
|
||||
|
||||
architectury {
|
||||
platformSetupLoomIde()
|
||||
fabric()
|
||||
}
|
||||
|
||||
configurations {
|
||||
common {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentFabric.extendsFrom common
|
||||
|
||||
// Files in this configuration will be bundled into your mod using the Shadow plugin.
|
||||
// Don"t use the `shadow` configuration from the plugin itself as it"s meant for excluding files.
|
||||
shadowBundle {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowBundle project(path: ":common", configuration: "transformProductionFabric")
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand version: project.version
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadowBundle]
|
||||
archiveClassifier = "dev-shadow"
|
||||
}
|
||||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
31
fabric/src/main/resources/fabric.mod.json
Normal file
31
fabric/src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "skinrestorer",
|
||||
"version": "${version}",
|
||||
"name": "SkinRestorer",
|
||||
"description": "A server-side mod for restoring skins on offline servers.",
|
||||
"authors": [
|
||||
"Lionarius"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://modrinth.com/mod/skinrestorer",
|
||||
"sources": "https://github.com/Suiranoil/SkinRestorer",
|
||||
"issues": "https://github.com/Suiranoil/SkinRestorer/issues"
|
||||
},
|
||||
"icon": "assets/skinrestorer/icon.png",
|
||||
"license": "MIT",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.lionarius.skinrestorer.fabric.SkinRestorerFabric"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"skinrestorer-common.mixins.json",
|
||||
"skinrestorer-fabric.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.15.10",
|
||||
"minecraft": ">=1.21"
|
||||
}
|
||||
}
|
||||
13
fabric/src/main/resources/skinrestorer-fabric.mixins.json
Normal file
13
fabric/src/main/resources/skinrestorer-fabric.mixins.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.lionarius.skinrestorer.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"CommandsMixin",
|
||||
"MinecraftServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,31 @@
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
org.gradle.parallel=true
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/versions.html
|
||||
minecraft_version=1.21
|
||||
yarn_mappings=1.21+build.2
|
||||
loader_version=0.15.11
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.2.6
|
||||
mod_version=2.0.0
|
||||
mod_id=skinrestorer
|
||||
minecraft_version=1.21
|
||||
enabled_platforms=fabric,neoforge
|
||||
maven_group=net.lionarius
|
||||
archives_base_name=skin-restorer
|
||||
archives_name=skin-restorer
|
||||
capitalized_name=SkinRestorer
|
||||
|
||||
# Mappings
|
||||
#yarn_mappings=1.21+build.4
|
||||
#yarn_mappings_patch_neoforge_version=1.21+build.4
|
||||
parchment_mappings=2024.06.23
|
||||
|
||||
# Fabric
|
||||
fabric_loader_version=0.15.11
|
||||
|
||||
# NeoForge
|
||||
neoforge_loader_version=21.0.0-beta
|
||||
|
||||
# Publish
|
||||
modrinth_id=ghrZDhGW
|
||||
curseforge_id=443823
|
||||
game_versions=1.21
|
||||
mod_loaders=fabric,neoforge
|
||||
|
||||
# Changelog Options
|
||||
changelog_max_commit_search=200
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
16
gradlew
vendored
16
gradlew
vendored
@@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (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.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# 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 ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
@@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# 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" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -202,11 +202,11 @@ fi
|
||||
# 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"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# 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 -- \
|
||||
"-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
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
||||
56
neoforge/build.gradle
Normal file
56
neoforge/build.gradle
Normal file
@@ -0,0 +1,56 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow"
|
||||
}
|
||||
|
||||
architectury {
|
||||
platformSetupLoomIde()
|
||||
neoForge()
|
||||
}
|
||||
|
||||
configurations {
|
||||
common {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentNeoForge.extendsFrom common
|
||||
|
||||
// Files in this configuration will be bundled into your mod using the Shadow plugin.
|
||||
// Don"t use the `shadow` configuration from the plugin itself as it"s meant for excluding files.
|
||||
shadowBundle {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "NeoForged"
|
||||
url = "https://maven.neoforged.net/releases"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
neoForge "net.neoforged:neoforge:$rootProject.neoforge_loader_version"
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowBundle project(path: ":common", configuration: "transformProductionNeoForge")
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("META-INF/neoforge.mods.toml") {
|
||||
expand version: project.version
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadowBundle]
|
||||
archiveClassifier = "dev-shadow"
|
||||
}
|
||||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
}
|
||||
1
neoforge/gradle.properties
Normal file
1
neoforge/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
loom.platform = neoforge
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
32
neoforge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
32
neoforge/src/main/resources/META-INF/neoforge.mods.toml
Normal file
@@ -0,0 +1,32 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[2,)"
|
||||
issueTrackerURL = "https://github.com/Suiranoil/SkinRestorer/issues"
|
||||
license = "MIT"
|
||||
|
||||
[[mods]]
|
||||
modId = "skinrestorer"
|
||||
version = "${version}"
|
||||
displayName = "SkinRestorer"
|
||||
authors = "Lionarius"
|
||||
logoFile = "assets/skinrestorer/icon.png"
|
||||
displayURL = "https://modrinth.com/mod/skinrestorer"
|
||||
description = '''
|
||||
A server-side mod for restoring skins on offline servers.
|
||||
'''
|
||||
|
||||
[[dependencies.skinrestorer]]
|
||||
modId = "neoforge"
|
||||
type = "required"
|
||||
versionRange = "[21.0.0-beta,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.skinrestorer]]
|
||||
modId = "minecraft"
|
||||
type = "required"
|
||||
versionRange = "[1.21,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[mixins]]
|
||||
config = "skinrestorer-common.mixins.json"
|
||||
@@ -1,9 +1,24 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
name = "Architectury"
|
||||
url = "https://maven.architectury.dev/"
|
||||
}
|
||||
maven {
|
||||
name = "Fabric"
|
||||
url = "https://maven.fabricmc.net/"
|
||||
}
|
||||
maven {
|
||||
name = "Forge"
|
||||
url = "https://files.minecraftforge.net/maven/"
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "skin-restorer"
|
||||
|
||||
include "common"
|
||||
include "fabric"
|
||||
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,129 +0,0 @@
|
||||
package net.lionarius.skinrestorer;
|
||||
|
||||
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.network.packet.s2c.play.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
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) {
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
PlayerManager playerManager = serverWorld.getServer().getPlayerManager();
|
||||
ServerChunkManager chunkManager = serverWorld.getChunkManager();
|
||||
|
||||
playerManager.sendToAll(new BundleS2CPacket(
|
||||
List.of(
|
||||
new PlayerRemoveS2CPacket(List.of(player.getUuid())),
|
||||
PlayerListS2CPacket.entryFromPlayer(Collections.singleton(player))
|
||||
)
|
||||
));
|
||||
chunkManager.unloadEntity(player);
|
||||
chunkManager.loadEntity(player);
|
||||
player.networkHandler.sendPacket(new BundleS2CPacket(
|
||||
List.of(
|
||||
new PlayerRespawnS2CPacket(player.createCommonPlayerSpawnInfo(serverWorld), PlayerRespawnS2CPacket.KEEP_ALL),
|
||||
new GameStateChangeS2CPacket(GameStateChangeS2CPacket.INITIAL_CHUNKS_COMING, 0)
|
||||
)
|
||||
));
|
||||
player.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
|
||||
player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player));
|
||||
player.sendAbilitiesUpdate();
|
||||
player.addExperience(0);
|
||||
playerManager.sendCommandTree(player);
|
||||
playerManager.sendWorldInfo(player, serverWorld);
|
||||
playerManager.sendPlayerStatus(player);
|
||||
playerManager.sendStatusEffects(player);
|
||||
}
|
||||
|
||||
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(2))
|
||||
.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(2))
|
||||
.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(2))
|
||||
.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()).requires(source -> source.hasPermissionLevel(2)).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