├── LICENSE
├── README.md
└── src
└── main
└── java
└── fr
└── trxyy
└── alternative
├── alternative_api_uiv2
└── components
│ ├── LauncherAlert.java
│ ├── LauncherButton.java
│ ├── LauncherImage.java
│ ├── LauncherLabel.java
│ ├── LauncherPasswordField.java
│ ├── LauncherProgressBar.java
│ ├── LauncherRectangle.java
│ ├── LauncherTextField.java
│ └── SwitchButton.java
├── alternative_apiv2
├── assets
│ ├── AssetIndex.java
│ ├── AssetIndexInfo.java
│ └── AssetObject.java
├── base
│ ├── AlternativeBase.java
│ ├── ApiConstants.java
│ ├── GameConnect.java
│ ├── GameEngine.java
│ ├── GameFolder.java
│ ├── GameLinks.java
│ ├── GameSize.java
│ ├── IScreen.java
│ ├── LauncherBackground.java
│ ├── LauncherBase.java
│ ├── LauncherPane.java
│ ├── LauncherPreferences.java
│ ├── ResourceLocation.java
│ └── WindowStyle.java
├── build
│ └── GameRunner.java
├── minecraft
│ ├── java
│ │ ├── DownloadJVMFile.java
│ │ ├── EnumJavaManifest.java
│ │ ├── JVMFile.java
│ │ ├── JVMManifest.java
│ │ ├── JavaManifest.java
│ │ ├── JavaRuntime.java
│ │ ├── JavaRuntimeAvailability.java
│ │ ├── JavaRuntimeVersion.java
│ │ └── JavaVersion.java
│ ├── json
│ │ ├── Argument.java
│ │ ├── ArgumentType.java
│ │ ├── DownloadInfo.java
│ │ ├── LibraryDownloadInfo.java
│ │ ├── MinecraftClient.java
│ │ ├── MinecraftLibrary.java
│ │ ├── MinecraftRules.java
│ │ ├── MinecraftSave.java
│ │ ├── MinecraftVersion.java
│ │ └── VersionsLister.java
│ ├── log4j
│ │ ├── Log4JPatch.java
│ │ ├── Log4jClient.java
│ │ ├── Log4jFile.java
│ │ └── Log4jLogging.java
│ └── utils
│ │ ├── Arch.java
│ │ ├── CompatibilityRule.java
│ │ ├── DateTypeAdapter.java
│ │ ├── Duplicator.java
│ │ ├── EnumJavaFileType.java
│ │ ├── FileUtil.java
│ │ ├── GameUtils.java
│ │ ├── JsonUtil.java
│ │ ├── LowerCaseEnumTypeAdapterFactory.java
│ │ ├── OSRestriction.java
│ │ ├── OperatingSystem.java
│ │ ├── Substitutor.java
│ │ └── Version.java
├── settings
│ ├── Encoder.java
│ ├── GameInfos.java
│ ├── GameSaver.java
│ └── UsernameSaver.java
├── updater
│ ├── Downloader.java
│ └── GameUpdater.java
└── utils
│ ├── FontLoader.java
│ └── Mover.java
└── alternative_authv2
├── base
├── AuthConfig.java
├── AuthConstants.java
├── Authenticator.java
├── EnumAuthConfig.java
├── GameAuth.java
├── Logger.java
├── Session.java
└── TokenGenerator.java
└── microsoft
├── AuthConstants.java
├── MicrosoftAuth.java
├── ParamType.java
└── model
├── DisplayClaims.java
├── MicrosoftModel.java
├── MinecraftMicrosoftModel.java
├── MinecraftProfileModel.java
├── MinecraftSkin.java
├── MinecraftStoreModel.java
├── StoreItem.java
├── XboxLiveModel.java
└── Xui.java
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 |
A JavaFX Library for Minecraft Launchers!
4 |
Works 100% on Windows, other OS need a Fix.
5 |
6 | ## Downloads
7 |
8 | - Download latest version [HERE](https://github.com/TrxyyDev/AlternativeAPI/releases/latest)
9 | - You can use my launcher sources [HERE](https://github.com/TrxyyDev/AlternativeAPI-launcher)
10 | - Web folder [HERE](https://mega.nz/file/q6h3QbKR#Alm6P2DKfPorcjIv6JfT2OcMHOs4fGnbHDIffA_YAzo)
11 | - Resources (for launcher) [HERE](https://mega.nz/file/ProWSSoZ#IzHCIfJsTbhty-U6GYSqlKQG7Dg3LBfbc6-FgA6Devw)
12 |
13 | ## Forge 1.13+ (deleting libraries)
14 |
15 | ```
16 | Go inside your libraries folder in your host.
17 | Go to libraries/com/google/guava/guava/
18 | And keep only the higher version, delete all others.
19 | ## OR
20 | Go inside your delete.cfg folder in your host
21 | and write a new line by putting the location of the guava libraries
22 | which are lower than the highest
23 |
24 | Example:
25 | libraries/com/google/guava/guava/15.0/guava-15.0.jar
26 | libraries/com/google/guava/guava/20.0/guava-20.0.jar
27 | libraries/com/google/guava/guava/21.0/guava-21.0.jar
28 |
29 | ```
30 | ## Distants files
31 |
32 | - ignore.cfg
33 | ```
34 | bin/game/servers.dat
35 | bin/game/options.txt
36 | bin/game/optionsshaders.txt
37 | bin/game/optionsof.txt
38 | bin/game/usercache.json
39 | bin/launcher_config.json
40 | bin/game/screenshots/
41 | bin/game/saves/
42 | bin/game/resourcepacks/
43 | bin/game/shaderpacks/
44 | bin/game/config/
45 | bin/game/mods/
46 | logs/
47 | ```
48 | - delete.cfg
49 | ```
50 | libraries/com/google/guava/guava/15.0/guava-15.0.jar
51 | ```
52 |
53 | ## How to Use
54 | ```
55 | private GameFolder gameFolder = new GameFolder("customlauncher");
56 | private LauncherPreferences launcherPreferences = new LauncherPreferences("Launcher Template AlternativeAPI", 950, 600, true);
57 | private GameLinks gameLinks = new GameLinks("http://127.0.0.1/alternative/1_16_3/", "1.16.3.json");
58 | private GameEngine gameEngine = new GameEngine(this.gameFolder, this.gameLinks, this.launcherPreferences, GameStyle.FORGE_1_13_HIGHER);
59 | private GameForge newForge = new GameForge("fmlclient", "34.1.0", "1.16.3", "net.minecraftforge", "20200911.084530");
60 | ```
61 |
62 |
63 |
64 | You can use NodeJS for better performances to check custom files
65 | - https://github.com/chaun14/AlternativeApi-NodeJS-Server-lite
66 | - https://github.com/chaun14/AlternativeApi-NodeJS-Server-full
67 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherAlert.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.scene.control.Alert;
4 | import javafx.scene.control.Alert.AlertType;
5 | import javafx.scene.control.Label;
6 | import javafx.scene.control.TextArea;
7 | import javafx.scene.layout.GridPane;
8 | import javafx.scene.layout.Priority;
9 |
10 | /**
11 | * @author Trxyy
12 | */
13 | public class LauncherAlert {
14 |
15 | /**
16 | * The Constructor
17 | * @param text The message to display
18 | * @param type The Type of the Alert
19 | */
20 | public LauncherAlert(String text, AlertType type) {
21 | Alert alert = new Alert(type);
22 | alert.setTitle("Error/Erreur");
23 | alert.setHeaderText(null);
24 | alert.setContentText(text);
25 | alert.showAndWait();
26 | }
27 |
28 | /**
29 | * The Constructor
30 | * @param title The title of the Alert
31 | * @param text The message to display
32 | */
33 | public LauncherAlert(String title, String text) {
34 | Alert alert = new Alert(AlertType.ERROR);
35 | alert.setTitle("Erreur");
36 | alert.setHeaderText("Argh! Une erreur est survenue.");
37 | alert.setContentText(title);
38 |
39 | Label label = new Label("L'exception est la suivante:");
40 | TextArea textArea = new TextArea(text);
41 | textArea.setEditable(false);
42 | textArea.setWrapText(true);
43 | textArea.setMaxWidth(Double.MAX_VALUE);
44 | textArea.setMaxHeight(Double.MAX_VALUE);
45 | GridPane.setVgrow(textArea, Priority.ALWAYS);
46 | GridPane.setHgrow(textArea, Priority.ALWAYS);
47 | GridPane expContent = new GridPane();
48 | expContent.setMaxWidth(Double.MAX_VALUE);
49 | expContent.add(label, 0, 0);
50 | expContent.add(textArea, 0, 1);
51 | alert.getDialogPane().setExpandableContent(expContent);
52 | alert.showAndWait();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherButton.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.event.EventHandler;
4 | import javafx.scene.control.Button;
5 | import javafx.scene.input.MouseEvent;
6 | import javafx.scene.layout.Pane;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class LauncherButton extends Button {
12 |
13 | /**
14 | * The Constructor
15 | * @param root The Pane to add the button
16 | */
17 | public LauncherButton(Pane root) {
18 | this.setUnHover(new EventHandler() {
19 | public void handle(MouseEvent event) {
20 | setOpacity(1.0);
21 | }
22 | });
23 | this.setHover(new EventHandler() {
24 | public void handle(MouseEvent event) {
25 | setOpacity(0.80);
26 | }
27 | });
28 | root.getChildren().add(this);
29 | }
30 |
31 | /**
32 | * The Constructor
33 | * @param root The Pane to add the button
34 | */
35 | public LauncherButton(String text, Pane root) {
36 | this.setText(text);
37 | this.setUnHover(new EventHandler() {
38 | public void handle(MouseEvent event) {
39 | setOpacity(1.0);
40 | }
41 | });
42 | this.setHover(new EventHandler() {
43 | public void handle(MouseEvent event) {
44 | setOpacity(0.80);
45 | }
46 | });
47 | root.getChildren().add(this);
48 | }
49 |
50 | /**
51 | * Set the size of the button
52 | * @param width_ The width
53 | * @param height_ The height
54 | */
55 | public void setSize(int width_, int height_) {
56 | this.setPrefSize(width_, height_);
57 | }
58 |
59 | /**
60 | * Set the button invisible
61 | */
62 | public void setInvisible() {
63 | this.setBackground(null);
64 | }
65 |
66 | /**
67 | * Set the position
68 | * @param posX The position X
69 | * @param posY The position Y
70 | */
71 | public void setPosition(int posX, int posY) {
72 | this.setLayoutX(posX);
73 | this.setLayoutY(posY);
74 | }
75 |
76 | /**
77 | * Set the position
78 | * @param posX The position X
79 | * @param posY The position Y
80 | */
81 | public void setBounds(int posX, int posY, int width_, int height_) {
82 | this.setLayoutX(posX);
83 | this.setLayoutY(posY);
84 | this.setPrefSize(width_, height_);
85 | }
86 |
87 | /**
88 | * Set the Action when clicked
89 | * @param value The value
90 | */
91 | public void setAction(EventHandler super MouseEvent> value) {
92 | this.onMouseClickedProperty().set(value);
93 | }
94 |
95 | /**
96 | * Set the Action when hover
97 | * @param value The value
98 | */
99 | public final void setHover(EventHandler super MouseEvent> value) {
100 | this.onMouseEnteredProperty().set(value);
101 | }
102 |
103 | /**
104 | * Set the Action when unhover
105 | * @param value The value
106 | */
107 | public final void setUnHover(EventHandler super MouseEvent> value) {
108 | this.onMouseExitedProperty().set(value);
109 | }
110 |
111 | /**
112 | * Set the Style
113 | * @param value The value
114 | */
115 | public final void addStyle(String value) {
116 | String finalValue = this.getStyle() + value;
117 | styleProperty().set(finalValue);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherImage.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.scene.image.Image;
4 | import javafx.scene.image.ImageView;
5 | import javafx.scene.layout.Pane;
6 |
7 | /**
8 | * @author Trxyy
9 | */
10 | public class LauncherImage extends ImageView {
11 |
12 | /**
13 | * The Constructor
14 | * @param root The Pane to add the image
15 | */
16 | public LauncherImage(Pane root) {
17 | root.getChildren().add(this);
18 | }
19 |
20 | /**
21 | * The Constructor
22 | * @param root The Pane to add the image
23 | * @param image The image
24 | */
25 | public LauncherImage(Pane root, Image image) {
26 | super(image);
27 | root.getChildren().add(this);
28 | }
29 |
30 | /**
31 | * Set the size
32 | * @param x The position X
33 | * @param y The position Y
34 | */
35 | public void setSize(int w, int h) {
36 | this.setFitWidth(w);
37 | this.setFitHeight(h);
38 | }
39 |
40 | /**
41 | * Set the bounds
42 | * @param x The position X
43 | * @param y The position Y
44 | */
45 | public void setBounds(int x, int y, int w, int h) {
46 | this.setLayoutX(x);
47 | this.setLayoutY(y);
48 | this.setFitWidth(w);
49 | this.setFitHeight(h);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherLabel.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.event.EventHandler;
4 | import javafx.scene.control.Label;
5 | import javafx.scene.input.MouseEvent;
6 | import javafx.scene.layout.Pane;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class LauncherLabel extends Label {
12 |
13 | /**
14 | * The Constructor
15 | * @param root The Pane to add the label
16 | */
17 | public LauncherLabel(Pane root) {
18 | root.getChildren().add(this);
19 | }
20 |
21 | /**
22 | * Set the label size
23 | * @param width_ The width
24 | * @param height_ The height
25 | */
26 | public void setSize(int width_, int height_) {
27 | this.setPrefSize(width_, height_);
28 | }
29 |
30 | /**
31 | * Set the label invisible
32 | */
33 | public void setInvisible() {
34 | this.setBackground(null);
35 | }
36 |
37 | /**
38 | * Set the position
39 | * @param posX The position X
40 | * @param posY The position Y
41 | */
42 | public void setPosition(int posX, int posY) {
43 | this.setLayoutX(posX);
44 | this.setLayoutY(posY);
45 | }
46 |
47 | /**
48 | * Set the position (double)
49 | * @param posX The position X (double)
50 | * @param posY The position Y (double)
51 | */
52 | public void setPosition(double posX, double posY) {
53 | this.setLayoutX(posX);
54 | this.setLayoutY(posY);
55 | }
56 |
57 | /**
58 | * Set the bounds (double)
59 | * @param posX The position X (double)
60 | * @param posY The position Y (double)
61 | */
62 | public void setBounds(double posX, double posY, int width_, int height_) {
63 | this.setLayoutX(posX);
64 | this.setLayoutY(posY);
65 | this.setPrefSize(width_, height_);
66 | }
67 |
68 | /**
69 | * Set the bounds (int)
70 | * @param posX The position X (int)
71 | * @param posY The position Y (int)
72 | */
73 | public void setBounds(int posX, int posY, int width_, int height_) {
74 | this.setLayoutX(posX);
75 | this.setLayoutY(posY);
76 | this.setPrefSize(width_, height_);
77 | }
78 |
79 | /**
80 | * Set the Action when clicked
81 | * @param value The value
82 | */
83 | public void setAction(EventHandler super MouseEvent> value) {
84 | this.onMouseClickedProperty().set(value);
85 | }
86 |
87 | /**
88 | * Set the Action when hover
89 | * @param value The value
90 | */
91 | public final void setHover(EventHandler super MouseEvent> value) {
92 | this.onMouseEnteredProperty().set(value);
93 | }
94 |
95 | /**
96 | * Set the Action when unhover
97 | * @param value The value
98 | */
99 | public final void setUnHover(EventHandler super MouseEvent> value) {
100 | this.onMouseExitedProperty().set(value);
101 | }
102 |
103 | /**
104 | * Set the Style
105 | * @param value The value
106 | */
107 | public final void addStyle(String value) {
108 | String finalValue = this.getStyle() + value;
109 | styleProperty().set(finalValue);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherPasswordField.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.event.EventHandler;
4 | import javafx.scene.control.PasswordField;
5 | import javafx.scene.input.MouseEvent;
6 | import javafx.scene.layout.Pane;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class LauncherPasswordField extends PasswordField {
12 |
13 | /**
14 | * The Constructor
15 | * @param root The Pane to add the field
16 | */
17 | public LauncherPasswordField(Pane root) {
18 | this.setSize(100, 30);
19 | this.setPosition(0, 0);
20 |
21 | this.setUnHover(new EventHandler() {
22 | public void handle(MouseEvent event) {
23 | setOpacity(1.0);
24 | }
25 | });
26 | this.setHover(new EventHandler() {
27 | public void handle(MouseEvent event) {
28 | setOpacity(0.80);
29 | }
30 | });
31 | root.getChildren().add(this);
32 | }
33 |
34 | /**
35 | * The Constructor
36 | * @param w The width
37 | * @param h The height
38 | * @param pX The position X
39 | * @param pY The position Y
40 | * @param root The Pane to add the field
41 | */
42 | public LauncherPasswordField(int w, int h, int pX, int pY, Pane root) {
43 | this.setSize(w, h);
44 | this.setPosition(pX, pY);
45 |
46 | this.setUnHover(new EventHandler() {
47 | public void handle(MouseEvent event) {
48 | setOpacity(1.0);
49 | }
50 | });
51 | this.setHover(new EventHandler() {
52 | public void handle(MouseEvent event) {
53 | setOpacity(0.80);
54 | }
55 | });
56 | root.getChildren().add(this);
57 | }
58 |
59 | /**
60 | * The Constructor
61 | * @param s The text by default
62 | * @param w The width
63 | * @param h The height
64 | * @param pX The position X
65 | * @param pY The position Y
66 | * @param root The Pane to add the field
67 | */
68 | public LauncherPasswordField(String s, int w, int h, int pX, int pY, Pane root) {
69 | this.setText(s);
70 | this.setSize(w, h);
71 | this.setPosition(pX, pY);
72 |
73 | this.setUnHover(new EventHandler() {
74 | public void handle(MouseEvent event) {
75 | setOpacity(1.0);
76 | }
77 | });
78 | this.setHover(new EventHandler() {
79 | public void handle(MouseEvent event) {
80 | setOpacity(0.80);
81 | }
82 | });
83 | root.getChildren().add(this);
84 | }
85 |
86 | /**
87 | * Set the size of the field
88 | * @param width_ The width
89 | * @param height_ The height
90 | */
91 | public void setSize(int width_, int height_) {
92 | this.setPrefSize(width_, height_);
93 | }
94 |
95 | /**
96 | * Set the position of the field
97 | * @param posX The position X
98 | * @param posY The position Y
99 | */
100 | public void setPosition(int posX, int posY) {
101 | this.setLayoutX(posX);
102 | this.setLayoutY(posY);
103 | }
104 |
105 | /**
106 | * Set the bounds of the field
107 | * @param posX The position X
108 | * @param posY The position Y
109 | * @param width_ The width
110 | * @param height_ The height
111 | */
112 | public void setBounds(int posX, int posY, int width_, int height_) {
113 | this.setLayoutX(posX);
114 | this.setLayoutY(posY);
115 | this.setPrefSize(width_, height_);
116 | }
117 |
118 | /**
119 | * Set the text to display when field is void
120 | * @param s The text to display
121 | */
122 | public void setVoidText(String s) {
123 | this.setPromptText(s);
124 | }
125 |
126 | /**
127 | * Set the Action when clicked
128 | * @param value The value
129 | */
130 | public void setAction(EventHandler super MouseEvent> value) {
131 | this.onMouseClickedProperty().set(value);
132 | }
133 |
134 | /**
135 | * Set the Action when hover
136 | * @param value The value
137 | */
138 | public final void setHover(EventHandler super MouseEvent> value) {
139 | this.onMouseEnteredProperty().set(value);
140 | }
141 |
142 | /**
143 | * Set the Action when unhover
144 | * @param value The value
145 | */
146 | public final void setUnHover(EventHandler super MouseEvent> value) {
147 | this.onMouseExitedProperty().set(value);
148 | }
149 |
150 | /**
151 | * Set the Style
152 | * @param value The value
153 | */
154 | public final void addStyle(String value) {
155 | String finalValue = this.getStyle() + value;
156 | styleProperty().set(finalValue);
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherProgressBar.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.scene.control.ProgressBar;
4 | import javafx.scene.layout.Pane;
5 |
6 | /**
7 | * @author Trxyy
8 | */
9 | public class LauncherProgressBar extends ProgressBar {
10 |
11 | /**
12 | * The current file name downloading
13 | */
14 | public String currentFile;
15 |
16 | /**
17 | * The Constructor
18 | */
19 | public LauncherProgressBar() {}
20 |
21 | /**
22 | * The Constructor
23 | * @param contentPane The Pane to add the progress bar
24 | */
25 | public LauncherProgressBar(Pane contentPane) {
26 | contentPane.getChildren().add(this);
27 | }
28 |
29 | /**
30 | * Set the size of the Progress bar
31 | * @param width_ The width
32 | * @param height_ The height
33 | */
34 | public void setSize(int width_, int height_) {
35 | this.setPrefSize(width_, height_);
36 | this.setWidth(width_);
37 | this.setHeight(height_);
38 | }
39 |
40 | /**
41 | * Set the size of the Progress bar (double)
42 | * @param width_ The width
43 | * @param height_ The height
44 | */
45 | public void setSize(double width_, double height_) {
46 | this.setPrefSize(width_, height_);
47 | this.setWidth(width_);
48 | this.setHeight(height_);
49 | }
50 |
51 | /**
52 | * Set the progress bar invisible
53 | */
54 | public void setInvisible() {
55 | this.setBackground(null);
56 | }
57 |
58 | /**
59 | * Set the position
60 | * @param posX The position X
61 | * @param posY The position Y
62 | */
63 | public void setPosition(int posX, int posY) {
64 | this.setLayoutX(posX);
65 | this.setLayoutY(posY);
66 | }
67 |
68 | /**
69 | * Set the position (double)
70 | * @param posX The position X (double)
71 | * @param posY The position Y (double)
72 | */
73 | public void setPosition(double posX, double posY) {
74 | this.setLayoutX(posX);
75 | this.setLayoutY(posY);
76 | }
77 | /**
78 | * Set the current file name
79 | * @param file The file name
80 | */
81 | public void setCurrentFile(String file) {
82 | this.currentFile = file;
83 | }
84 |
85 | /**
86 | * @return The current file name
87 | */
88 | public String getCurrentFile() {
89 | return this.currentFile;
90 | }
91 |
92 | /**
93 | * Set the bounds
94 | * @param posX The position X
95 | * @param posY The position Y
96 | * @param width The size X
97 | * @param height The size Y
98 | */
99 | public void setBounds(int posX, int posY, int width, int height) {
100 | this.setLayoutX(posX);
101 | this.setLayoutY(posY);
102 | this.setPrefSize(width, height);
103 | }
104 |
105 | /**
106 | * Set the Style
107 | * @param value The value
108 | */
109 | public final void addStyle(String value) {
110 | String finalValue = this.getStyle() + value;
111 | styleProperty().set(finalValue);
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherRectangle.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.scene.layout.Pane;
4 | import javafx.scene.paint.Color;
5 | import javafx.scene.shape.Rectangle;
6 |
7 | /**
8 | * @author Trxyy
9 | */
10 | public class LauncherRectangle extends Rectangle {
11 |
12 | /**
13 | * The Constructor
14 | * @param root The pane to ad the rectangle
15 | * @param x The position X
16 | * @param y The position Y
17 | * @param sX The size X
18 | * @param sY The size Y
19 | */
20 | public LauncherRectangle(Pane root, int x, int y, int sX, int sY) {
21 | this.setX(x);
22 | this.setY(y);
23 | this.setWidth(sX);
24 | this.setHeight(sY);
25 | root.getChildren().add(this);
26 | }
27 |
28 | /**
29 | * The Constructor
30 | * @param width The width
31 | * @param height The height
32 | */
33 | public LauncherRectangle(int width, int height) {
34 | this.setWidth(width);
35 | this.setHeight(height);
36 | }
37 |
38 | /**
39 | * Set the color of the rectangle
40 | * @param color The color
41 | */
42 | public void setColor(Color color) {
43 | this.setStroke(color);
44 | }
45 |
46 | /**
47 | * Set the Style
48 | * @param value The value
49 | */
50 | public final void addStyle(String value) {
51 | String finalValue = this.getStyle() + value;
52 | styleProperty().set(finalValue);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/LauncherTextField.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.event.EventHandler;
4 | import javafx.scene.control.TextField;
5 | import javafx.scene.input.MouseEvent;
6 | import javafx.scene.layout.Pane;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class LauncherTextField extends TextField {
12 |
13 | /**
14 | * The Constructor
15 | * @param root The Pane to add the field
16 | */
17 | public LauncherTextField(Pane root) {
18 | this.setSize(100, 30);
19 | this.setPosition(0, 0);
20 | this.setUnHover(new EventHandler() {
21 | public void handle(MouseEvent event) {
22 | setOpacity(1.0);
23 | }
24 | });
25 | this.setHover(new EventHandler() {
26 | public void handle(MouseEvent event) {
27 | setOpacity(0.80);
28 | }
29 | });
30 | root.getChildren().add(this);
31 | }
32 |
33 | /**
34 | * The Constructor
35 | * @param s The text by default
36 | * @param root The pane to add the field
37 | */
38 | public LauncherTextField(String s, Pane root) {
39 | this.setText(s);
40 | this.setSize(100, 30);
41 | this.setPosition(0, 0);
42 | this.setUnHover(new EventHandler() {
43 | public void handle(MouseEvent event) {
44 | setOpacity(1.0);
45 | }
46 | });
47 | this.setHover(new EventHandler() {
48 | public void handle(MouseEvent event) {
49 | setOpacity(0.80);
50 | }
51 | });
52 | root.getChildren().add(this);
53 | }
54 |
55 | /**
56 | * The Constructor
57 | * @param w The width
58 | * @param h The height
59 | * @param pX The position X
60 | * @param pY The position Y
61 | * @param root The Pane to add the field
62 | */
63 | public LauncherTextField(int w, int h, int pX, int pY, Pane root) {
64 | this.setSize(w, h);
65 | this.setPosition(pX, pY);
66 | root.getChildren().add(this);
67 | }
68 |
69 | /**
70 | * The Constructor
71 | * @param s The text by default
72 | * @param w The width
73 | * @param h The height
74 | * @param pX The position X
75 | * @param pY The position Y
76 | * @param root The Pane to add the field
77 | */
78 | public LauncherTextField(String s, int w, int h, int pX, int pY, Pane root) {
79 | this.setText(s);
80 | this.setSize(w, h);
81 | this.setPosition(pX, pY);
82 | this.setUnHover(new EventHandler() {
83 | public void handle(MouseEvent event) {
84 | setOpacity(1.0);
85 | }
86 | });
87 | this.setHover(new EventHandler() {
88 | public void handle(MouseEvent event) {
89 | setOpacity(0.80);
90 | }
91 | });
92 | root.getChildren().add(this);
93 | }
94 |
95 | /**
96 | * Set the size of the field
97 | * @param width_ The width
98 | * @param height_ The height
99 | */
100 | public void setSize(int width_, int height_) {
101 | this.setPrefSize(width_, height_);
102 | }
103 |
104 | /**
105 | * Set the position of the field
106 | * @param posX The position X
107 | * @param posY The position Y
108 | */
109 | public void setPosition(int posX, int posY) {
110 | this.setLayoutX(posX);
111 | this.setLayoutY(posY);
112 | }
113 |
114 | /**
115 | * Set the bounds of the field
116 | * @param posX The position X
117 | * @param posY The position Y
118 | * @param width_ The width
119 | * @param height_ The height
120 | */
121 | public void setBounds(int posX, int posY, int width_, int height_) {
122 | this.setLayoutX(posX);
123 | this.setLayoutY(posY);
124 | this.setPrefSize(width_, height_);
125 | }
126 |
127 | /**
128 | * Set the text to display when field is void
129 | * @param s The text to display
130 | */
131 | public void setVoidText(String s) {
132 | this.setPromptText(s);
133 | }
134 |
135 | /**
136 | * Set the Action when clicked
137 | * @param value The value
138 | */
139 | public void setAction(EventHandler super MouseEvent> value) {
140 | this.onMouseClickedProperty().set(value);
141 | }
142 |
143 | /**
144 | * Set the Action when hover
145 | * @param value The value
146 | */
147 | public final void setHover(EventHandler super MouseEvent> value) {
148 | this.onMouseEnteredProperty().set(value);
149 | }
150 |
151 | /**
152 | * Set the Action when unhover
153 | * @param value The value
154 | */
155 | public final void setUnHover(EventHandler super MouseEvent> value) {
156 | this.onMouseExitedProperty().set(value);
157 | }
158 |
159 | /**
160 | * Set the Style
161 | * @param value The value
162 | */
163 | public final void addStyle(String value) {
164 | String finalValue = this.getStyle() + value;
165 | styleProperty().set(finalValue);
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_api_uiv2/components/SwitchButton.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_api_uiv2.components;
2 |
3 | import javafx.event.Event;
4 | import javafx.event.EventHandler;
5 | import javafx.geometry.Pos;
6 | import javafx.scene.control.Button;
7 | import javafx.scene.layout.StackPane;
8 | import javafx.scene.paint.Color;
9 | import javafx.scene.shape.Circle;
10 | import javafx.scene.shape.Rectangle;
11 |
12 | public class SwitchButton extends StackPane {
13 | private final Rectangle back = new Rectangle(30, 10, Color.RED);
14 | private final Button button = new Button();
15 | private String buttonStyleOff = "-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.2), 0.2, 0.0, 0.0, 2); -fx-background-color: WHITE;";
16 | private String buttonStyleOn = "-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.2), 0.2, 0.0, 0.0, 2); -fx-background-color: #00893d;";
17 | private boolean state;
18 |
19 | private void init() {
20 | getChildren().addAll(back, button);
21 | setMinSize(30, 15);
22 | back.maxWidth(30);
23 | back.minWidth(30);
24 | back.maxHeight(10);
25 | back.minHeight(10);
26 | back.setArcHeight(back.getHeight());
27 | back.setArcWidth(back.getHeight());
28 | back.setFill(Color.valueOf("#ced5da"));
29 | Double r = 2.0;
30 | button.setShape(new Circle(r));
31 | setAlignment(button, Pos.CENTER_LEFT);
32 | button.setMaxSize(15, 15);
33 | button.setMinSize(15, 15);
34 | button.setStyle(buttonStyleOff);
35 | }
36 |
37 | public SwitchButton() {
38 | init();
39 | EventHandler click = new EventHandler() {
40 | @Override
41 | public void handle(Event e) {
42 | if (state) {
43 | button.setStyle(buttonStyleOff);
44 | back.setFill(Color.valueOf("#ced5da"));
45 | setAlignment(button, Pos.CENTER_LEFT);
46 | state = false;
47 | } else {
48 | button.setStyle(buttonStyleOn);
49 | back.setFill(Color.valueOf("#80C49E"));
50 | setAlignment(button, Pos.CENTER_RIGHT);
51 | state = true;
52 | }
53 | }
54 | };
55 |
56 | button.setFocusTraversable(false);
57 | setOnMouseClicked(click);
58 | button.setOnMouseClicked(click);
59 | }
60 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/assets/AssetIndex.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.assets;
2 |
3 | import java.util.HashSet;
4 | import java.util.LinkedHashMap;
5 | import java.util.Map;
6 | import java.util.Set;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class AssetIndex {
12 | /**
13 | * The default asset name
14 | */
15 | public static final String DEFAULT_ASSET_NAME = "legacy";
16 | /**
17 | * The objects stocked inside a Map
18 | */
19 | private final Map objects;
20 | /**
21 | * Is Virtual ?
22 | */
23 | private boolean virtual;
24 |
25 | /**
26 | * The Constructor
27 | */
28 | public AssetIndex() {
29 | this.objects = new LinkedHashMap();
30 | }
31 |
32 | /**
33 | * @return The objects list as a Map
34 | */
35 | public Map getObjects() {
36 | return this.objects;
37 | }
38 |
39 | /**
40 | * @return Get the unique Objects as a Set
41 | */
42 | public Set getUniqueObjects() {
43 | return new HashSet(this.objects.values());
44 | }
45 |
46 | /**
47 | * @return If it's virtual
48 | */
49 | public boolean isVirtual() {
50 | return this.virtual;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/assets/AssetIndexInfo.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.assets;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.DownloadInfo;
4 |
5 | /**
6 | * @author Trxyy
7 | */
8 | public class AssetIndexInfo extends DownloadInfo {
9 | /**
10 | * The assetIndex
11 | */
12 | protected String id;
13 | /**
14 | * The total size of all Objects
15 | */
16 | protected long totalSize;
17 | /**
18 | * Is known
19 | */
20 | protected boolean known = true;
21 |
22 | /**
23 | * The Constructor
24 | */
25 | public AssetIndexInfo() {
26 | }
27 |
28 | /**
29 | * The Constructor
30 | * @param id_ The assetIndex id
31 | */
32 | public AssetIndexInfo(String id_) {
33 | this.id = id_;
34 | this.url = constantURL("https://s3.amazonaws.com/Minecraft.Download/indexes/" + id + ".json");
35 | this.known = false;
36 | }
37 |
38 | /**
39 | * @return The total size
40 | */
41 | public long getTotalSize() {
42 | return this.totalSize;
43 | }
44 |
45 | /**
46 | * @return The assetIndex id
47 | */
48 | public String getId() {
49 | return this.id;
50 | }
51 |
52 | /**
53 | * @return If the Size and Hash is known
54 | */
55 | public boolean sizeAndHashKnown() {
56 | return this.known;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/assets/AssetObject.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.assets;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class AssetObject {
7 | /**
8 | * The hash
9 | */
10 | private String hash;
11 | /**
12 | * The size
13 | */
14 | private long size;
15 |
16 | /**
17 | * @return The hash of the object
18 | */
19 | public String getHash() {
20 | return this.hash;
21 | }
22 |
23 | /**
24 | * @return The size
25 | */
26 | public long getSize() {
27 | return this.size;
28 | }
29 |
30 | /**
31 | * @return If is equals
32 | */
33 | @Override
34 | public boolean equals(Object other) {
35 | if (this == other)
36 | return true;
37 | if ((other == null) || (getClass() != other.getClass()))
38 | return false;
39 |
40 | AssetObject that = (AssetObject) other;
41 |
42 | if (this.size != that.size)
43 | return false;
44 | return this.hash.equals(that.hash);
45 | }
46 |
47 | /**
48 | * @return The hashcode
49 | */
50 | @Override
51 | public int hashCode() {
52 | int result = this.hash.hashCode();
53 | result = 31 * result + (int) (this.size ^ this.size >>> 32);
54 | return result;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/AlternativeBase.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import javafx.application.Application;
4 | import javafx.stage.Stage;
5 |
6 | /**
7 | * @author Trxyy
8 | */
9 | public abstract class AlternativeBase extends Application {
10 | /**
11 | * The resource location
12 | */
13 | private static ResourceLocation RESOURCE_LOCATION = new ResourceLocation();
14 | /**
15 | * The start function (called by JavaFX before all)
16 | */
17 | public abstract void start(Stage primaryStage) throws Exception;
18 |
19 | /**
20 | * @return The resourcelocation
21 | */
22 | public ResourceLocation getResourceLocation() {
23 | return RESOURCE_LOCATION;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/ApiConstants.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | public class ApiConstants {
4 |
5 | public static String API_VERSION = "1.6.0";
6 | public static String AUTHOR = "Trxyy";
7 |
8 | public static String getVersion() {
9 | return API_VERSION;
10 | }
11 |
12 | public static String getAuthor() {
13 | return AUTHOR;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/GameConnect.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class GameConnect {
7 |
8 | /**
9 | * The Ip adress of the server in question
10 | */
11 | public String ip;
12 |
13 | /**
14 | * The Port of the server in question
15 | */
16 | public String port;
17 |
18 | /**
19 | * The Constructor
20 | * @param i The server Ip
21 | * @param p The server Port
22 | */
23 | public GameConnect(String i, String p) {
24 | this.ip = i;
25 | this.port = p;
26 | }
27 |
28 | /**
29 | * @return The Ip for direct connect to server
30 | */
31 | public String getIp() {
32 | return this.ip;
33 | }
34 |
35 | /**
36 | * @return The Port for direct connect to server
37 | */
38 | public String getPort() {
39 | return this.port;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/GameEngine.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.MinecraftVersion;
4 | import fr.trxyy.alternative.alternative_apiv2.updater.GameUpdater;
5 | import javafx.stage.Stage;
6 |
7 | public class GameEngine {
8 | /**
9 | * The GameFolder, folder hierarchy
10 | */
11 | private GameFolder gameFolder;
12 | /**
13 | * The GameLinks, the links for the json, ignore, delete & status file
14 | */
15 | private GameLinks gameLinks;
16 | /**
17 | * The LauncherPreferences, the name, size, ismoveable, resourceLocation
18 | */
19 | private LauncherPreferences launcherSize;
20 | /**
21 | * The Stage, the stage in question to use in other class.
22 | */
23 | private Stage fakeBase;
24 | /**
25 | * MinecraftVersion, the Minecraft version from the json
26 | */
27 | private MinecraftVersion minecraftVersion;
28 | private GameConnect gameConnect;
29 | private GameSize gameSize;
30 | private GameUpdater minecraftUpdater;
31 |
32 | /**
33 | * The Constructor
34 | *
35 | * @param folder The GameFolder for the folder name in APPDATA
36 | * @param links The links where the updater need to update
37 | */
38 | public GameEngine(GameFolder folder, GameLinks links, LauncherPreferences lSize) {
39 | this.gameFolder = folder;
40 | this.gameLinks = links;
41 | this.launcherSize = lSize;
42 | this.gameSize = GameSize.DEFAULT;
43 | }
44 |
45 | public GameFolder getGameFolder() {
46 | return this.gameFolder;
47 | }
48 |
49 | public LauncherPreferences getLauncherPreferences() {
50 | return this.launcherSize;
51 | }
52 |
53 | public GameLinks getGameLinks() {
54 | return this.gameLinks;
55 | }
56 |
57 | public int getWidth() {
58 | return this.getLauncherPreferences().getWidth();
59 | }
60 |
61 | public int getHeight() {
62 | return this.getLauncherPreferences().getHeight();
63 | }
64 |
65 | /**
66 | * Register some things...
67 | *
68 | * @param version Register The minecraft version from json
69 | */
70 | public void reg(MinecraftVersion version) {
71 | this.minecraftVersion = version;
72 | }
73 |
74 | /**
75 | * Register some things...
76 | *
77 | * @param connect Register The GameConnect object
78 | */
79 | public void reg(GameConnect connect) {
80 | this.gameConnect = connect;
81 | }
82 | /**
83 | * Register some things...
84 | *
85 | * @param connect Register The GameSize object
86 | */
87 | public void reg(GameSize connect) {
88 | this.gameSize = connect;
89 | }
90 | /**
91 | * Register some things...
92 | *
93 | * @param upd Register The MinecraftUpdater object
94 | */
95 | public void reg(GameUpdater upd) {
96 | this.minecraftUpdater = upd;
97 | }
98 | /**
99 | * Register some things...
100 | *
101 | * @param base Register the current stage to use
102 | */
103 | public void reg(Stage base) {
104 | this.fakeBase = base;
105 | }
106 |
107 | /**
108 | * @return The Stage
109 | */
110 | public Stage getStage() {
111 | return this.fakeBase;
112 | }
113 |
114 | /**
115 | * @return Minecraft version from Json
116 | */
117 | public MinecraftVersion getMinecraftVersion() {
118 | return this.minecraftVersion;
119 | }
120 |
121 | /**
122 | * @return The Server and Port of the direct connect
123 | */
124 | public GameConnect getGameConnect() {
125 | return this.gameConnect;
126 | }
127 |
128 | public GameSize getGameSize() {
129 | return this.gameSize;
130 | }
131 |
132 | public GameUpdater getGameUpdater() {
133 | return this.minecraftUpdater;
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/GameFolder.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import java.io.File;
4 |
5 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.GameUtils;
6 |
7 | /**
8 | * @author Trxyy
9 | */
10 | public class GameFolder {
11 |
12 | /**
13 | * The main game directory
14 | */
15 | public File gameDir;
16 | /**
17 | * The cache directory
18 | */
19 | public File cacheDir;
20 | /**
21 | * The versions directory, where the game is placed
22 | */
23 | public File versionsDir;
24 | /**
25 | * The resourcepacks folder
26 | */
27 | public File resourcepackDir;
28 | /**
29 | * The libraries directory, where the libraries are placed
30 | */
31 | public File libsDir;
32 | /**
33 | * The assets directory, where the assets are placed
34 | */
35 | public File assetsDir;
36 | /**
37 | * The logging configuration directory, where the log4j configuration files are placed
38 | */
39 | public File log_configsDir;
40 | /**
41 | * The natives directory, where the natives are placed
42 | */
43 | public File nativesDir;
44 | /**
45 | * The natives cache directory, where the natives are placed until unzipped inside natives directory
46 | */
47 | public File nativesCacheDir;
48 | /**
49 | * The runtime directory
50 | */
51 | public File runtimeDir;
52 |
53 | /**
54 | * The Constructor
55 | * @param location The folder name (inside APPDATA, if minecraft = .minecraft; if myserver = .myserver)
56 | */
57 | public GameFolder(String location) {
58 | this.gameDir = GameUtils.getWorkingDirectory(location);
59 | this.assetsDir = new File(this.gameDir, "assets");
60 | this.libsDir = new File(this.gameDir, "libraries");
61 | this.versionsDir = new File(this.gameDir, "versions");
62 | this.resourcepackDir = new File(this.gameDir, "resourcepacks");
63 | this.cacheDir = new File(this.gameDir, "cache");
64 | this.log_configsDir = new File(this.assetsDir, "log_configs");
65 | this.nativesDir = new File(this.gameDir, "natives");
66 | this.nativesCacheDir = new File(this.gameDir, "cache_natives");
67 | this.runtimeDir = new File(this.gameDir, "runtime");
68 |
69 | /** ----- Creating missing folders -------- */
70 | this.getLibsDir().mkdirs();
71 | this.getCacheDir().mkdirs();
72 | this.getAssetsDir().mkdirs();
73 | this.getLogConfigsDir().mkdirs();
74 | this.getGameDir().mkdirs();
75 | this.getNativesDir().mkdirs();
76 | this.getNativesCacheDir().mkdirs();
77 | this.getVersionsDir().mkdirs();
78 | this.getRuntimeDir().mkdirs();
79 | }
80 |
81 | public File getRuntimeDir() {
82 | return this.runtimeDir;
83 | }
84 |
85 | /**
86 | * @return The log_configs directory
87 | */
88 | public File getLogConfigsDir() {
89 | return this.log_configsDir;
90 | }
91 |
92 | /**
93 | * @return The game directory
94 | */
95 | public File getGameDir() {
96 | return this.gameDir;
97 | }
98 |
99 | /**
100 | * @return The cache directory
101 | */
102 | public File getCacheDir() {
103 | return this.cacheDir;
104 | }
105 |
106 | /**
107 | * @return The play directory (game placed)
108 | */
109 | public File getVersionsDir() {
110 | return this.versionsDir;
111 | }
112 |
113 | /**
114 | * @return The game jar (minecraft.jar
115 | */
116 | public File getresourcepackDir() {
117 | return this.resourcepackDir;
118 | }
119 |
120 | /**
121 | * @return The libraries directory
122 | */
123 | public File getLibsDir() {
124 | return this.libsDir;
125 | }
126 |
127 | /**
128 | * @return The assets directory
129 | */
130 | public File getAssetsDir() {
131 | return this.assetsDir;
132 | }
133 |
134 | /**
135 | * @return The natives directory
136 | */
137 | public File getNativesDir() {
138 | return this.nativesDir;
139 | }
140 |
141 | /**
142 | * @return The natives cache directory
143 | */
144 | public File getNativesCacheDir() {
145 | return this.nativesCacheDir;
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/GameLinks.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class GameLinks {
7 |
8 | /**
9 | * The base url, ex: http://mywebsite.com/
10 | */
11 | public String BASE_URL;
12 | /**
13 | * The json url, ex: http://mywebsite.com/mc_version.json
14 | */
15 | public String JSON_URL;
16 | /**
17 | * The json name, 1.7.10.json for 1.7.10 version
18 | */
19 | public String JSON_NAME;
20 | /**
21 | * The ignore list, ex: http://mywebsite.com/ignore.cfg
22 | */
23 | public String IGNORE_LIST;
24 | /**
25 | * The delete list, ex: http://mywebsite.com/delete.cfg
26 | */
27 | public String DELETE_LIST;
28 | /**
29 | * The custom files url, ex: http://mywebsite.com/files/
30 | */
31 | public String CUSTOM_FILES_URL;
32 |
33 | /**
34 | * The Constructor
35 | *
36 | * @param baseUrl The base url
37 | * @param jsonName The json name (1.7.10.json for 1.7.10 version)
38 | */
39 | public GameLinks(String baseUrl, String jsonName) {
40 | if (baseUrl.endsWith("/")) {
41 | this.BASE_URL = baseUrl;
42 | } else {
43 | this.BASE_URL = baseUrl + "/";
44 | }
45 | this.JSON_URL = baseUrl + jsonName;
46 | this.JSON_NAME = jsonName;
47 | this.IGNORE_LIST = baseUrl + "ignore.cfg";
48 | this.DELETE_LIST = baseUrl + "delete.cfg";
49 | this.CUSTOM_FILES_URL = baseUrl + "files/";
50 | }
51 |
52 | /**
53 | * @return The url
54 | */
55 | public String getBaseUrl() {
56 | return this.BASE_URL;
57 | }
58 |
59 | /**
60 | * @return The json name
61 | */
62 | public String getJsonName() {
63 | return this.JSON_NAME;
64 | }
65 |
66 | /**
67 | * @return The json url
68 | */
69 | public String getJsonUrl() {
70 | return this.JSON_URL;
71 | }
72 |
73 | /**
74 | * @return The ignore list url
75 | */
76 | public String getIgnoreListUrl() {
77 | return this.IGNORE_LIST;
78 | }
79 |
80 | /**
81 | * @return The delete list url
82 | */
83 | public String getDeleteListUrl() {
84 | return this.DELETE_LIST;
85 | }
86 |
87 | /**
88 | * @return The custom files folder url
89 | */
90 | public String getCustomFilesUrl() {
91 | return this.CUSTOM_FILES_URL;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/GameSize.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public enum GameSize {
7 |
8 | DEFAULT("854x480", 854, 480),
9 | SIZE_1024x768("1024x768", 1024, 768),
10 | SIZE_1280x1024("1280x1024", 1280, 1024),
11 | SIZE_1366x768("1366x768", 1366, 768),
12 | SIZE_1600x900("1600x900", 1600, 900),
13 | SIZE_1920x1080("1920x1080", 1920, 1080),
14 | SIZE_2560x1440("2560x1440", 2560, 1440);
15 |
16 | /**
17 | * The size to display
18 | */
19 | public String description;
20 | /**
21 | * The game width
22 | */
23 | public int width;
24 | /**
25 | * The game height
26 | */
27 | public int height;
28 |
29 | /**
30 | * The Constructor
31 | * @param desc The size to display
32 | * @param w The width
33 | * @param h The height
34 | */
35 | GameSize(String desc, int w, int h) {
36 | this.description = desc;
37 | this.width = w;
38 | this.height = h;
39 | }
40 |
41 | /**
42 | * @return The description to display
43 | */
44 | public String getDesc() {
45 | return this.description;
46 | }
47 |
48 | /**
49 | * @return The width
50 | */
51 | public String getWidth() {
52 | return "" + this.width;
53 | }
54 |
55 | /**
56 | * @return The height
57 | */
58 | public String getHeight() {
59 | return "" + this.height;
60 | }
61 |
62 | /**
63 | * @param i The value as a int
64 | * @return The GameSize from the int
65 | */
66 | public static GameSize getWindowSize(int i) {
67 | if (i == 0) {
68 | return GameSize.DEFAULT;
69 | } else if (i == 1) {
70 | return GameSize.SIZE_1024x768;
71 | } else if (i == 2) {
72 | return GameSize.SIZE_1280x1024;
73 | } else if (i == 3) {
74 | return GameSize.SIZE_1366x768;
75 | } else if (i == 4) {
76 | return GameSize.SIZE_1600x900;
77 | } else if (i == 5) {
78 | return GameSize.SIZE_1920x1080;
79 | } else if (i == 6) {
80 | return GameSize.SIZE_2560x1440;
81 | }
82 | return GameSize.DEFAULT;
83 | }
84 |
85 | /**
86 | * @param value The value as a String
87 | * @return The GameSize from the String
88 | */
89 | public static int getWindowSize(String value) {
90 | if (value.equals("854x480")) {
91 | return 0;
92 | } else if (value.equals("1024x768")) {
93 | return 1;
94 | } else if (value.equals("1280x1024")) {
95 | return 2;
96 | } else if (value.equals("1366x768")) {
97 | return 3;
98 | } else if (value.equals("1600x900")) {
99 | return 4;
100 | } else if (value.equals("1920x1080")) {
101 | return 5;
102 | } else if (value.equals("2560x1440")) {
103 | return 6;
104 | }
105 | return 0;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/IScreen.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import java.awt.Desktop;
4 | import java.awt.MouseInfo;
5 | import java.awt.image.BufferedImage;
6 | import java.io.BufferedInputStream;
7 | import java.io.BufferedOutputStream;
8 | import java.io.File;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.net.HttpURLConnection;
12 | import java.net.URI;
13 | import java.net.URISyntaxException;
14 | import java.net.URL;
15 |
16 | import javax.imageio.ImageIO;
17 |
18 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.MinecraftVersion;
19 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.JsonUtil;
20 | import fr.trxyy.alternative.alternative_apiv2.updater.GameUpdater;
21 | import fr.trxyy.alternative.alternative_apiv2.utils.Mover;
22 | import fr.trxyy.alternative.alternative_authv2.base.GameAuth;
23 | import fr.trxyy.alternative.alternative_authv2.base.Logger;
24 | import fr.trxyy.alternative.alternative_authv2.base.Session;
25 | import javafx.animation.AnimationTimer;
26 | import javafx.animation.FadeTransition;
27 | import javafx.embed.swing.SwingFXUtils;
28 | import javafx.scene.Node;
29 | import javafx.scene.Parent;
30 | import javafx.scene.Scene;
31 | import javafx.scene.image.Image;
32 | import javafx.scene.image.ImageView;
33 | import javafx.scene.layout.Pane;
34 | import javafx.scene.media.Media;
35 | import javafx.scene.media.MediaPlayer;
36 | import javafx.scene.media.MediaView;
37 | import javafx.scene.paint.Color;
38 | import javafx.scene.shape.Rectangle;
39 | import javafx.stage.Modality;
40 | import javafx.stage.Stage;
41 | import javafx.util.Duration;
42 |
43 | /**
44 | * @author Trxyy
45 | */
46 | public class IScreen {
47 | /**
48 | * The resource location
49 | */
50 | private ResourceLocation RESOURCE_LOCATION = new ResourceLocation();
51 | /**
52 | * The Minecraft Version
53 | */
54 | private MinecraftVersion minecraftVersion;
55 | /**
56 | * The logo Image
57 | */
58 | private ImageView logoImage;
59 | /**
60 | * The position X
61 | */
62 | private int posX = 0;
63 | /**
64 | * The position Y
65 | */
66 | private int posY = 0;
67 |
68 | /**
69 | * The Constructor
70 | * @param engine The GameEngine instance
71 | * @param img The image
72 | * @param posX_ The position X
73 | * @param posY_ The position Y
74 | * @param sizeX The size X
75 | * @param sizeY The size Y
76 | * @param root The Pane to add
77 | * @param animate The enum for animate logo or not
78 | */
79 | public void drawImage(GameEngine engine, Image img, int posX_, int posY_, int sizeX, int sizeY, Pane root, Mover animate) {
80 | this.logoImage = new ImageView();
81 | this.logoImage.setImage(img);
82 | this.logoImage.setFitWidth(sizeX);
83 | this.logoImage.setFitHeight(sizeY);
84 | this.posX = posX_;
85 | this.posY = posY_;
86 | this.logoImage.setLayoutX(this.posX);
87 | this.logoImage.setLayoutY(this.posY);
88 | root.getChildren().add(this.logoImage);
89 | if (animate.equals(Mover.MOVE)) {
90 | animateLogo();
91 | }
92 | }
93 |
94 | /**
95 | * To animate the logo
96 | */
97 | private void animateLogo() {
98 | AnimationTimer animate = new AnimationTimer() {
99 | public void handle(long now) {
100 | float multplicatorSize = 54.25F;
101 | int mouseX = (MouseInfo.getPointerInfo().getLocation()).x;
102 | int mouseY = (MouseInfo.getPointerInfo().getLocation()).y;
103 | logoImage.setLayoutX((posX - mouseX / multplicatorSize));
104 | logoImage.setLayoutY((posY - mouseY / multplicatorSize));
105 | }
106 | };
107 | animate.start();
108 | }
109 |
110 | /**
111 | * Draw a background image
112 | * @param engine The GameEngine instance
113 | * @param root The pane to add
114 | * @param img The image name
115 | */
116 | public void drawBackgroundImage(GameEngine engine, Pane root, String img) {
117 | ImageView backgroundImage = new ImageView();
118 | backgroundImage.setImage(getResourceLocation().loadImage(engine, img));
119 | backgroundImage.setFitWidth(engine.getLauncherPreferences().getWidth());
120 | backgroundImage.setFitHeight(engine.getLauncherPreferences().getHeight());
121 | backgroundImage.setLayoutX(0);
122 | backgroundImage.setLayoutY(0);
123 | root.getChildren().add(backgroundImage);
124 | }
125 |
126 | /**
127 | * Draw a animated background (mp4)
128 | * @param engine The GameEngine instance
129 | * @param root The Pane to add
130 | * @param media The Media name
131 | */
132 | public void drawAnimatedBackground(GameEngine engine, Pane root, String media) {
133 | MediaPlayer player = new MediaPlayer(getResourceLocation().getMedia(engine, media));
134 | MediaView viewer = new MediaView(player);
135 | viewer.setFitWidth(engine.getLauncherPreferences().getWidth());
136 | viewer.setFitHeight(engine.getLauncherPreferences().getHeight());
137 | player.setAutoPlay(true);
138 | viewer.setPreserveRatio(false);
139 | player.setCycleCount(-1);
140 | player.play();
141 | root.getChildren().add(viewer);
142 | }
143 |
144 | /**
145 | * Load a image
146 | * @param image The image name
147 | * @return The image loaded in Swing and converted to FX
148 | */
149 | public Image loadImage(String image) {
150 | BufferedImage bufferedImage = null;
151 | try {
152 | Logger.log(" " + getResourceLocation() + image);
153 | bufferedImage = ImageIO.read(IScreen.class.getResourceAsStream(getResourceLocation() + image));
154 | } catch (IOException e) {
155 | Logger.log("Echec du chargement de la ressource demandee.");
156 | }
157 | Image fxImage = SwingFXUtils.toFXImage(bufferedImage, null);
158 | return fxImage;
159 | }
160 |
161 | /**
162 | * @param engine The GameEngine instance
163 | * @param image The image as a string
164 | * @return The Image from the string
165 | */
166 | public Image loadImage(GameEngine engine, String image) {
167 | BufferedImage bufferedImage = null;
168 | try {
169 | bufferedImage = ImageIO.read(ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + image));
170 | } catch (IOException iOException) {
171 | }
172 | return SwingFXUtils.toFXImage(bufferedImage, null);
173 | }
174 |
175 | /**
176 | * Open a link
177 | * @param urlString The url to open
178 | */
179 | public void openLink(String urlString) {
180 | try {
181 | Desktop.getDesktop().browse(new URL(urlString).toURI());
182 | } catch (Exception e) {
183 | e.printStackTrace();
184 | }
185 | }
186 |
187 | /**
188 | * Play a sound
189 | * @param sound The sound name
190 | */
191 | public void playSound(String sound) {
192 | URL resourceUrl = IScreen.class.getResource(getResourceLocation() + sound);
193 | Media theMedia = null;
194 | try {
195 | theMedia = new Media(resourceUrl.toURI().toString());
196 | } catch (URISyntaxException e) {
197 | Logger.log(e.toString());
198 | }
199 | final MediaPlayer mediaPlayer = new MediaPlayer(theMedia);
200 | mediaPlayer.play();
201 | }
202 |
203 | public Rectangle drawRect(Pane root, int x, int y, int w, int h, Color r) {
204 | Rectangle rect = new Rectangle();
205 | rect.setX(x);
206 | rect.setY(y);
207 | rect.setWidth(w);
208 | rect.setHeight(h);
209 | rect.setFill(r);
210 | root.getChildren().add(rect);
211 | return rect;
212 | }
213 |
214 | /**
215 | * @return The resource location
216 | */
217 | public ResourceLocation getResourceLocation() {
218 | return RESOURCE_LOCATION;
219 | }
220 |
221 | public FadeTransition fadeOut(Node object, int time) {
222 | FadeTransition ft = new FadeTransition(Duration.millis(time), object);
223 | ft.setFromValue(1.0);
224 | ft.setToValue(0.0);
225 | ft.play();
226 | return ft;
227 | }
228 |
229 | public FadeTransition fadeIn(Node object, int time) {
230 | FadeTransition ft = new FadeTransition(Duration.millis(time), object);
231 | ft.setFromValue(0.0);
232 | ft.setToValue(1.0);
233 | ft.play();
234 | return ft;
235 | }
236 |
237 | public void showMicrosoftAuth(GameEngine engine, GameAuth auth) {
238 | Scene scene = new Scene(createMicrosoftPanel(engine, auth));
239 | Stage stage = new Stage();
240 | scene.setFill(Color.TRANSPARENT);
241 | stage.setResizable(false);
242 | stage.setTitle("Microsoft Authentication");
243 | stage.setWidth(500);
244 | stage.setHeight(600);
245 | stage.setScene(scene);
246 | stage.initModality(Modality.APPLICATION_MODAL);
247 | stage.showAndWait();
248 | }
249 |
250 | private Parent createMicrosoftPanel(GameEngine engine, GameAuth auth) {
251 | LauncherPane contentPane = new LauncherPane(engine);
252 | auth.connectMicrosoft(contentPane, engine);
253 | return contentPane;
254 | }
255 |
256 | public MinecraftVersion prepareGameUpdate(GameUpdater updater, GameEngine engine, Session session, File jsonFile) {
257 | String json = null;
258 | try {
259 | json = JsonUtil.loadJSONFile(jsonFile);
260 | } catch (IOException e) {
261 | e.printStackTrace();
262 | }
263 | return minecraftVersion = (MinecraftVersion) JsonUtil.getGson().fromJson(json, MinecraftVersion.class);
264 | }
265 |
266 | public void downloadGameAndRun(GameUpdater updater, Session session) {
267 | updater.updateAssets();
268 | updater.updateJars();
269 | updater.downloadJavaManifest();
270 | updater.updateLog4j();
271 | updater.runGame(session);
272 | }
273 |
274 | /**
275 | * Download Minecraft Json version at Every Launch to be up to date.
276 | * @throws URISyntaxException
277 | */
278 | public File downloadVersion(String urlVers, GameEngine engine) {
279 | URI uri = null;
280 | try {
281 | uri = new URI(urlVers);
282 | } catch (URISyntaxException e1) {
283 | e1.printStackTrace();
284 | }
285 | String path = uri.getPath();
286 | String idStr = path.substring(path.lastIndexOf('/') + 1);
287 | System.out.println("Trying to download " + idStr);
288 |
289 | File versionIdFolder = null;
290 | versionIdFolder = new File(engine.getGameFolder().getVersionsDir(), idStr.replace(".json", ""));
291 |
292 | versionIdFolder.mkdirs();
293 | File theFile = new File(versionIdFolder, idStr);
294 | try {
295 | URL url = new URL(urlVers);
296 | HttpURLConnection connection = (HttpURLConnection) url.openConnection();
297 | float totalDataRead = 0;
298 | BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
299 | FileOutputStream fos = new FileOutputStream(theFile);
300 | BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
301 | byte[] data = new byte[1024];
302 | int i = 0;
303 | while ((i = in.read(data, 0, 1024)) >= 0) {
304 | totalDataRead = totalDataRead + i;
305 | bout.write(data, 0, i);
306 | }
307 | bout.close();
308 | in.close();
309 | } catch (Exception e) {
310 | e.printStackTrace();
311 | System.exit(0);
312 | }
313 | return theFile;
314 | }
315 |
316 | }
317 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/LauncherBackground.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import java.awt.image.BufferedImage;
4 | import java.io.IOException;
5 | import java.net.URISyntaxException;
6 | import java.net.URL;
7 |
8 | import javax.imageio.ImageIO;
9 |
10 | import javafx.embed.swing.SwingFXUtils;
11 | import javafx.scene.image.Image;
12 | import javafx.scene.image.ImageView;
13 | import javafx.scene.layout.Pane;
14 | import javafx.scene.media.Media;
15 | import javafx.scene.media.MediaPlayer;
16 | import javafx.scene.media.MediaView;
17 |
18 | /**
19 | * @author Trxyy
20 | */
21 | public class LauncherBackground {
22 | /**
23 | * The position X
24 | */
25 | public int posX;
26 | /**
27 | * The position Y
28 | */
29 | public int posY;
30 | /**
31 | * The MediaPlayer, video for background
32 | */
33 | public static MediaPlayer player;
34 | /**
35 | * The opacity of the video
36 | */
37 | public static double opacity = 1.0D;
38 | /**
39 | * The MediaView, required for the Player
40 | */
41 | public static MediaView viewer;
42 |
43 | /**
44 | * The Constructor
45 | * @param engine The GameEngine instance
46 | * @param mediaName The media
47 | * @param root The Pane to add the background
48 | */
49 | public LauncherBackground(GameEngine engine, String mediaName, Pane root) {
50 | this.posX = 0;
51 | this.posY = 0;
52 | if (mediaName.endsWith(".mp4") || mediaName.endsWith(".avi") || mediaName.endsWith(".mov")) {
53 | player = new MediaPlayer(getMedia(engine, mediaName));
54 | viewer = new MediaView(player);
55 | viewer.setFitWidth(engine.getLauncherPreferences().getWidth());
56 | viewer.setFitHeight(engine.getLauncherPreferences().getHeight());
57 | player.setAutoPlay(true);
58 | viewer.setPreserveRatio(false);
59 | viewer.setOpacity(opacity);
60 | player.setCycleCount(-1);
61 | player.play();
62 | root.getChildren().add(viewer);
63 | } else {
64 | ImageView backgroundImage = new ImageView();
65 | backgroundImage.setImage(loadImage(engine, mediaName));
66 | backgroundImage.setFitWidth(engine.getLauncherPreferences().getWidth());
67 | backgroundImage.setFitHeight(engine.getLauncherPreferences().getHeight());
68 | backgroundImage.setLayoutX(0);
69 | backgroundImage.setLayoutY(0);
70 | root.getChildren().add(backgroundImage);
71 | }
72 | }
73 |
74 | /**
75 | * @param engine The GameEngine instance
76 | * @param image The image as a string
77 | * @return The Image from the string
78 | */
79 | public Image loadImage(GameEngine engine, String image) {
80 | BufferedImage bufferedImage = null;
81 | try {
82 | bufferedImage = ImageIO.read(ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + image));
83 | } catch (IOException iOException) {
84 | }
85 | return SwingFXUtils.toFXImage(bufferedImage, null);
86 | }
87 |
88 | public Media getMedia(GameEngine engine, String media) {
89 | Media theMedia = null;
90 | URL resourceUrl = ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + media);
91 | try {
92 | theMedia = new Media(resourceUrl.toURI().toString());
93 | } catch (URISyntaxException e) {
94 | e.printStackTrace();
95 | }
96 | return theMedia;
97 | }
98 |
99 | /**
100 | * The Constructor
101 | * @param engine The GameEngine instance
102 | * @param f The media
103 | * @param opa The opacity
104 | * @param root The Pane to add the background
105 | */
106 | public LauncherBackground(GameEngine engine, Media f, double opa, Pane root) {
107 | this.posX = 0;
108 | this.posY = 0;
109 | MediaPlayer player = new MediaPlayer(f);
110 | MediaView viewer = new MediaView(player);
111 | viewer.setFitWidth(engine.getLauncherPreferences().getWidth());
112 | viewer.setFitHeight(engine.getLauncherPreferences().getHeight());
113 | player.setAutoPlay(true);
114 | viewer.setPreserveRatio(false);
115 | viewer.setOpacity(opa);
116 | player.setCycleCount(-1);
117 | player.play();
118 |
119 | root.getChildren().add(viewer);
120 | }
121 |
122 | /**
123 | * The Constructor
124 | * @param f The media
125 | * @param posX The position X
126 | * @param posY The position Y
127 | * @param sizeX The size X
128 | * @param sizeYThe size Y
129 | * @param root The Pane to add the background
130 | */
131 | public LauncherBackground(Media f, int posX, int posY, int sizeX, int sizeY, Pane root) {
132 | this.posX = 0;
133 | this.posY = 0;
134 | MediaPlayer player = new MediaPlayer(f);
135 | MediaView viewer = new MediaView(player);
136 | viewer.setFitWidth(sizeX);
137 | viewer.setFitHeight(sizeY);
138 | viewer.setLayoutX(posX);
139 | viewer.setLayoutX(posY);
140 | player.setAutoPlay(true);
141 | viewer.setPreserveRatio(false);
142 | viewer.setOpacity(opacity);
143 | player.setCycleCount(-1);
144 | player.play();
145 |
146 | root.getChildren().add(viewer);
147 | }
148 |
149 | /**
150 | * The Constructor
151 | * @param f The media
152 | * @param posX The position X
153 | * @param posY The position Y
154 | * @param sizeX The size X
155 | * @param sizeYThe size Y
156 | * @param opa The opacity
157 | * @param root The Pane to add the background
158 | */
159 | public LauncherBackground(Media f, int posX, int posY, int sizeX, int sizeY, double opa, Pane root) {
160 | this.posX = 0;
161 | this.posY = 0;
162 | MediaPlayer player = new MediaPlayer(f);
163 | MediaView viewer = new MediaView(player);
164 | viewer.setFitWidth(sizeX);
165 | viewer.setFitHeight(sizeY);
166 | viewer.setLayoutX(posX);
167 | viewer.setLayoutX(posY);
168 | player.setAutoPlay(true);
169 | viewer.setPreserveRatio(false);
170 | viewer.setOpacity(opa);
171 | player.setCycleCount(-1);
172 | player.play();
173 |
174 | root.getChildren().add(viewer);
175 | }
176 |
177 | /**
178 | * Set the opacity
179 | * @param opaci The opacity
180 | */
181 | public static void setOpacity(double opaci) {
182 | opacity = opaci;
183 | }
184 |
185 | /**
186 | * @return The MediaPlayer
187 | */
188 | public static MediaPlayer getPlayer() {
189 | return player;
190 | }
191 |
192 | /**
193 | * @return The MediaView
194 | */
195 | public static MediaView getViewer() {
196 | return viewer;
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/LauncherBase.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import java.awt.Point;
4 | import java.awt.image.BufferedImage;
5 | import java.io.IOException;
6 |
7 | import javax.imageio.ImageIO;
8 |
9 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.OperatingSystem;
10 | import fr.trxyy.alternative.alternative_apiv2.utils.Mover;
11 | import fr.trxyy.alternative.alternative_authv2.base.Logger;
12 | import javafx.application.Platform;
13 | import javafx.embed.swing.SwingFXUtils;
14 | import javafx.event.EventHandler;
15 | import javafx.scene.Scene;
16 | import javafx.scene.image.Image;
17 | import javafx.scene.input.MouseEvent;
18 | import javafx.scene.paint.Color;
19 | import javafx.stage.Stage;
20 | import javafx.stage.StageStyle;
21 | import javafx.stage.WindowEvent;
22 |
23 | /**
24 | * @author Trxyy
25 | */
26 | public class LauncherBase {
27 |
28 | /**
29 | * The point where the mouse is clicked
30 | */
31 | final Point dragDelta = new Point();
32 |
33 | /**
34 | * The GameEngine instance
35 | */
36 | public GameEngine gameEngine;
37 |
38 | /**
39 | * The Constructor
40 | * @param stage The primary stage
41 | * @param scene The Scene
42 | * @param style The Stage Style (Transparent etc...
43 | * @param engine The GameEngine instance
44 | */
45 | public LauncherBase(final Stage stage, Scene scene, StageStyle style, GameEngine engine) {
46 | this.gameEngine = engine;
47 |
48 | if (OperatingSystem.getCurrentPlatform() == OperatingSystem.OSX || OperatingSystem.getCurrentPlatform() == OperatingSystem.LINUX || OperatingSystem.getCurrentPlatform() == OperatingSystem.SOLARIS) {
49 | Logger.log("Il semblerait que vous utilisiez Mac/Linux.");
50 | Logger.log("Si vous rencontrez des difficultes, rendez-vous sur:");
51 | Logger.log("https://alternativeapi.forumactif.com/t80-demarrer-son-launcher-sur-linux-openjfx");
52 | }
53 |
54 | engine.reg(stage);
55 |
56 | stage.initStyle(style);
57 | if (style.equals(StageStyle.TRANSPARENT)) {
58 | scene.setFill(Color.TRANSPARENT);
59 | }
60 | stage.setResizable(false);
61 | stage.setTitle(engine.getLauncherPreferences().getName());
62 | stage.setWidth(engine.getLauncherPreferences().getWidth());
63 | stage.setHeight(engine.getLauncherPreferences().getHeight());
64 | stage.setOnCloseRequest(new EventHandler() {
65 | public void handle(WindowEvent windowEvent) {
66 | Platform.exit();
67 | System.exit(0);
68 | }
69 | });
70 | if (engine.getLauncherPreferences().isMovable().equals(Mover.MOVE)) {
71 | scene.setOnMousePressed(new EventHandler() {
72 | public void handle(MouseEvent mouseEvent) {
73 | dragDelta.x = (int) (stage.getX() - mouseEvent.getScreenX());
74 | dragDelta.y = (int) (stage.getY() - mouseEvent.getScreenY());
75 | }
76 | });
77 | scene.setOnMouseDragged(new EventHandler() {
78 | public void handle(MouseEvent mouseEvent) {
79 | stage.setX(mouseEvent.getScreenX() + dragDelta.x);
80 | stage.setY(mouseEvent.getScreenY() + dragDelta.y);
81 | }
82 | });
83 | }
84 | stage.setScene(scene);
85 | this.displayCopyrights();
86 |
87 | // if (engine.isOnline()) {
88 | // if (engine.getGameMaintenance() != null) {
89 | // if (engine.getGameMaintenance().getMaintenance().equals(Maintenance.USE)) {
90 | // String result = "";
91 | // try {
92 | // result = engine.getGameMaintenance().readMaintenance();
93 | // } catch (IOException e) {
94 | // e.printStackTrace();
95 | // }
96 | // if (!result.equals("Ok")) {
97 | // engine.getGameMaintenance().setAccessBlocked(true);
98 | // new LauncherAlert("" + result, AlertType.WARNING);
99 | // } else {
100 | // stage.show();
101 | // }
102 | // } else {
103 | // stage.show();
104 | // }
105 | // } else {
106 | // stage.show();
107 | // }
108 | // }
109 | // else {
110 | stage.show();
111 | // }
112 |
113 | }
114 |
115 | /**
116 | * Set the Icon Image of the window
117 | * @param primaryStage The Stage to set the icon
118 | * @param img The image
119 | */
120 | public void setIconImage(Stage primaryStage, String imgName) {
121 | Image img = loadImage(this.gameEngine, imgName);
122 | primaryStage.getIcons().add(img);
123 | }
124 |
125 | /**
126 | * @param engine The GameEngine instance
127 | * @param image The image as a string
128 | * @return The Image from the string
129 | */
130 | public Image loadImage(GameEngine engine, String image) {
131 | BufferedImage bufferedImage = null;
132 | try {
133 | bufferedImage = ImageIO.read(ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + image));
134 | } catch (IOException iOException) {
135 | }
136 | return SwingFXUtils.toFXImage(bufferedImage, null);
137 | }
138 |
139 | /**
140 | * Display some copyrights
141 | */
142 | private void displayCopyrights() {
143 | Logger.log("========================================");
144 | Logger.log("| AlternativeUpdater |");
145 | Logger.log("| Version: " + ApiConstants.getVersion() + " |");
146 | Logger.log("========================================");
147 | }
148 |
149 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/LauncherPane.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import javafx.scene.layout.Pane;
4 | import javafx.scene.shape.Rectangle;
5 |
6 | /**
7 | * @author Trxyy
8 | */
9 | public class LauncherPane extends Pane {
10 |
11 | /**
12 | * The Constructor
13 | * @param gameEngine The GameEngine instance
14 | */
15 |
16 | private GameEngine gameEngine;
17 |
18 | public LauncherPane(GameEngine engine) {
19 | this.gameEngine = engine;
20 | this.setPrefSize(engine.getLauncherPreferences().getWidth(), engine.getLauncherPreferences().getHeight());
21 | }
22 |
23 | public LauncherPane(GameEngine engine, double size, WindowStyle style) {
24 | this.gameEngine = engine;
25 | this.setPrefSize(engine.getLauncherPreferences().getWidth(), engine.getLauncherPreferences().getHeight());
26 |
27 | if (size != 0) {
28 | this.setCorners(size);
29 | }
30 |
31 | if (style.equals(WindowStyle.TRANSPARENT)) {
32 | this.setTransparent();
33 | }
34 |
35 | }
36 |
37 | public void setCorners(double size) {
38 | Rectangle rect = new Rectangle(this.gameEngine.getLauncherPreferences().getWidth(), this.gameEngine.getLauncherPreferences().getHeight());
39 | rect.setArcHeight(size);
40 | rect.setArcWidth(size);
41 | this.setClip(rect);
42 | }
43 |
44 | public void setTransparent() {
45 | this.setStyle("-fx-background-color: transparent;");
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/LauncherPreferences.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.utils.Mover;
4 |
5 | /**
6 | * @author Trxyy
7 | */
8 | public class LauncherPreferences {
9 |
10 | /**
11 | * The launcher name
12 | */
13 | public String name;
14 | /**
15 | * The launcher width
16 | */
17 | public int width;
18 | /**
19 | * The launcher height
20 | */
21 | public int height;
22 | /**
23 | * If the window is moveable or not
24 | */
25 | public Mover moveable;
26 | /**
27 | * The resource location in package
28 | */
29 | public String resourceLocation;
30 |
31 | /**
32 | * The Constructor
33 | * @param n The launcher name
34 | * @param w The launcher size width
35 | * @param h The launcher size height
36 | * @param m If the window is moveable or not
37 | */
38 | public LauncherPreferences(String n, int w, int h, Mover m) {
39 | this.name = n;
40 | this.width = w;
41 | this.height = h;
42 | this.moveable = m;
43 | this.resourceLocation = "/resources/";
44 | }
45 |
46 | /**
47 | * @return The width
48 | */
49 | public int getWidth() {
50 | return this.width;
51 | }
52 |
53 | /**
54 | * @return The height
55 | */
56 | public int getHeight() {
57 | return this.height;
58 | }
59 |
60 | /**
61 | * @return The launcher name (title window)
62 | */
63 | public String getName() {
64 | return this.name;
65 | }
66 |
67 | /**
68 | * @return The resource location
69 | */
70 | public String getResourceLocation() {
71 | return this.resourceLocation;
72 | }
73 |
74 | /**
75 | * @return If the launcher window is movable by a click or not
76 | */
77 | public Mover isMovable() {
78 | return this.moveable;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/ResourceLocation.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | import java.awt.image.BufferedImage;
4 | import java.io.IOException;
5 | import java.net.URISyntaxException;
6 | import java.net.URL;
7 |
8 | import javax.imageio.ImageIO;
9 |
10 | import javafx.embed.swing.SwingFXUtils;
11 | import javafx.scene.image.Image;
12 | import javafx.scene.media.Media;
13 |
14 | /**
15 | * @author Trxyy
16 | */
17 | public class ResourceLocation {
18 |
19 | /**
20 | * @param engine The GameEngine instance
21 | * @param media The Media as a string
22 | * @return The Media from the string
23 | */
24 | public Media getMedia(GameEngine engine, String media) {
25 | Media theMedia = null;
26 | URL resourceUrl = ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + media);
27 | try {
28 | theMedia = new Media(resourceUrl.toURI().toString());
29 | } catch (URISyntaxException e) {
30 | e.printStackTrace();
31 | }
32 | return theMedia;
33 | }
34 |
35 | /**
36 | * @param engine The GameEngine instance
37 | * @param image The image as a string
38 | * @return The Image from the string
39 | */
40 | public Image loadImage(GameEngine engine, String image) {
41 | BufferedImage bufferedImage = null;
42 | try {
43 | bufferedImage = ImageIO.read(ResourceLocation.class.getResource(String.valueOf(engine.getLauncherPreferences().getResourceLocation()) + image));
44 | } catch (IOException iOException) {
45 | }
46 | return SwingFXUtils.toFXImage(bufferedImage, null);
47 | }
48 |
49 | /**
50 | * @param image The image as a String
51 | * @return A Buffered Image for AWT
52 | */
53 | public BufferedImage loadImageAWT(String image) {
54 | BufferedImage bufferedImage = null;
55 | try {
56 | bufferedImage = ImageIO.read(ResourceLocation.class.getResourceAsStream(String.valueOf("/resources/") + image));
57 | } catch (IOException iOException) {
58 | }
59 | return bufferedImage;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/base/WindowStyle.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public enum WindowStyle {
7 | TRANSPARENT, BASIC;
8 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/DownloadJVMFile.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.DownloadInfo;
4 |
5 | public class DownloadJVMFile {
6 | private DownloadInfo lzma;
7 | private DownloadInfo raw;
8 |
9 | public DownloadJVMFile(DownloadJVMFile o) {
10 | this.lzma = o.lzma;
11 | this.raw = o.raw;
12 | }
13 |
14 | public DownloadInfo getLzma() {
15 | return this.lzma;
16 | }
17 |
18 | public DownloadInfo getRaw() {
19 | return this.raw;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/EnumJavaManifest.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | public enum EnumJavaManifest {
4 | GAMECORE("gamecore"),
5 | LINUX("linux"),
6 | LINUX_i386("linux-i386"),
7 | MACOS("mac-os"),
8 | WINDOWS_64("windows-x64"),
9 | WINDOWS_86("windows-x86");
10 |
11 | private String name;
12 |
13 | EnumJavaManifest(String u) {
14 | this.name = u;
15 | }
16 |
17 | public String getName() {
18 | return this.name;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JVMFile.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | public class JVMFile {
4 | private DownloadJVMFile downloads;
5 |
6 | private boolean executable;
7 | private String type;
8 | private String target;
9 |
10 | public JVMFile(JVMFile o) {
11 | this.executable = o.executable;
12 | this.type = o.type;
13 | this.target = o.target;
14 | }
15 |
16 | public DownloadJVMFile getDownloads() {
17 | return this.downloads;
18 | }
19 |
20 | public boolean isExecutable() {
21 | return this.executable;
22 | }
23 |
24 | public String getType() {
25 | return this.type;
26 | }
27 |
28 | public String getTarget() {
29 | return this.target;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JVMManifest.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | import java.util.Map;
4 |
5 | public class JVMManifest {
6 |
7 | public Map files;
8 |
9 | public JVMManifest(JVMManifest o) {
10 | this.files = o.files;
11 | }
12 |
13 | public Map getFiles() {
14 | return this.files;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JavaManifest.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.Arch;
9 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.OperatingSystem;
10 |
11 | public class JavaManifest {
12 |
13 | public Map> gamecore;
14 | public Map> linux;
15 | @SerializedName("linux-i386")
16 | public Map> linuxI386;
17 | @SerializedName("mac-os")
18 | public Map> macos;
19 | @SerializedName("windows-x64")
20 | public Map> windows64;
21 | @SerializedName("windows-x86")
22 | public Map> windows86;
23 |
24 | public JavaManifest(JavaManifest o) {
25 | this.gamecore = o.gamecore;
26 | this.linux = o.linux;
27 | this.linuxI386 = o.linuxI386;
28 | this.macos = o.macos;
29 | this.windows64 = o.windows64;
30 | this.windows86 = o.windows86;
31 | }
32 |
33 | public String getCurrentOS() {
34 | switch (OperatingSystem.getCurrentPlatform()) {
35 | case WINDOWS:
36 | if (!OperatingSystem.getJavaBit().equals(Arch.x64)) {
37 | return "windows-x86";
38 | }
39 | return "windows-x64";
40 | case OSX:
41 | return "mac-os";
42 | case LINUX:
43 | if (!OperatingSystem.getJavaBit().equals(Arch.x64)) {
44 | return "linux-i386";
45 | }
46 | return "linux";
47 | default:
48 | return "unknown";
49 | }
50 | }
51 |
52 | public Map> getCurrentJava() {
53 | switch (OperatingSystem.getCurrentPlatform()) {
54 | case WINDOWS:
55 | if (!OperatingSystem.getJavaBit().equals(Arch.x64)) {
56 | return windows86;
57 | }
58 | return windows64;
59 | case OSX:
60 | return macos;
61 | case LINUX:
62 | if (!OperatingSystem.getJavaBit().equals(Arch.x64)) {
63 | return linuxI386;
64 | }
65 | return linux;
66 | default:
67 | return gamecore;
68 | }
69 | }
70 |
71 | public Map> getGamecore() {
72 | return gamecore;
73 | }
74 |
75 | public Map> getLinux() {
76 | return linux;
77 | }
78 |
79 | public Map> getLinuxI386() {
80 | return linuxI386;
81 | }
82 |
83 | public Map> getMacos() {
84 | return macos;
85 | }
86 |
87 | public Map> getWindows64() {
88 | return windows64;
89 | }
90 |
91 | public Map> getWindows86() {
92 | return windows86;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JavaRuntime.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.DownloadInfo;
4 |
5 | public class JavaRuntime {
6 | public JavaRuntimeAvailability availability;
7 | public DownloadInfo manifest;
8 | public JavaRuntimeVersion version;
9 |
10 | public JavaRuntime() {
11 |
12 | }
13 |
14 | public JavaRuntime(JavaRuntime o) {
15 | this.availability = o.availability;
16 | this.manifest = o.manifest;
17 | this.version = o.version;
18 | }
19 |
20 | public JavaRuntimeAvailability getAvailability() {
21 | return availability;
22 | }
23 |
24 | public DownloadInfo getManifest() {
25 | return manifest;
26 | }
27 |
28 | public JavaRuntimeVersion getVersion() {
29 | return version;
30 | }
31 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JavaRuntimeAvailability.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | public class JavaRuntimeAvailability {
4 | public int group;
5 | public int progress;
6 |
7 | public JavaRuntimeAvailability(JavaRuntimeAvailability o) {
8 | this.group = o.group;
9 | this.progress = o.progress;
10 | }
11 |
12 | public int getGroup() {
13 | return group;
14 | }
15 |
16 | public int getProgress() {
17 | return progress;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JavaRuntimeVersion.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | public class JavaRuntimeVersion {
4 | public String name;
5 | public String released;
6 |
7 | public JavaRuntimeVersion(JavaRuntimeVersion o) {
8 | this.name = o.name;
9 | this.released = o.released;
10 | }
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public String getReleased() {
17 | return released;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/java/JavaVersion.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.java;
2 |
3 | public class JavaVersion {
4 |
5 | private String component;
6 | private int majorVersion;
7 |
8 | private JavaVersion(JavaVersion o) {
9 | this.component = o.component;
10 | this.majorVersion = o.majorVersion;
11 | }
12 |
13 | public String getComponent() {
14 | return this.component;
15 | }
16 |
17 | public int getMajorVersion() {
18 | return this.majorVersion;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/Argument.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.lang.reflect.Type;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import com.google.gson.JsonArray;
8 | import com.google.gson.JsonDeserializationContext;
9 | import com.google.gson.JsonDeserializer;
10 | import com.google.gson.JsonElement;
11 | import com.google.gson.JsonObject;
12 | import com.google.gson.JsonParseException;
13 |
14 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.CompatibilityRule;
15 |
16 | /**
17 | * @author Trxyy
18 | */
19 | public class Argument {
20 | /**
21 | * The values
22 | */
23 | public final String[] values;
24 | /**
25 | * The compatibility Rules in a List
26 | */
27 | private final List rules;
28 |
29 | /**
30 | *
31 | * @param values
32 | * @param compatibilityRules
33 | */
34 | public Argument(String[] values, List compatibilityRules) {
35 | this.values = values;
36 | this.rules = compatibilityRules;
37 | }
38 |
39 | /**
40 | * @return the argument values
41 | */
42 | public String[] getValues() {
43 | return values;
44 | }
45 |
46 | // public String[] getValues() {
47 | //
48 | // for (int i = 0; i < rules.size(); i++) {
49 | // if (rules.get(i).getOs().isCurrentOperatingSystem()) {
50 | // Logger.log("RULE ADDED ! " + values);
51 | // return this.values;
52 | // }
53 | // }
54 | //
55 | // return new String[] { "NOPE" };
56 | // }
57 |
58 | /**
59 | * @return The Arguments
60 | */
61 | // public String getArguments() {
62 | //
63 | // for (int i = 0; i < rules.size(); i++) {
64 | // if (rules.get(i).getOs().isCurrentOperatingSystem()) {
65 | // Logger.log("RULE ADDED ! " + values[i]);
66 | // }
67 | // }
68 | //
69 | // for (String value : this.values) {
70 | // return value;
71 | // }
72 | // return "null";
73 | // }
74 |
75 | // public String getArguments() {
76 | // for (String value : this.values) {
77 | // return value;
78 | // }
79 | // return "null";
80 | // }
81 |
82 | public String getArguments() {
83 | if (this.appliesToCurrentEnvironment())
84 | for (String value : this.values) {
85 | return value;
86 | }
87 | return "";
88 | }
89 |
90 | /**
91 | * @return If allow or not compatibility
92 | */
93 | public boolean appliesToCurrentEnvironment() {
94 | if (this.rules == null)
95 | return true;
96 | CompatibilityRule.Action lastAction = CompatibilityRule.Action.DISALLOW;
97 | for (CompatibilityRule compatibilityRule : this.rules) {
98 | CompatibilityRule.Action action = compatibilityRule.getAppliedAction();
99 | if (action != null)
100 | lastAction = action;
101 | }
102 | return (lastAction == CompatibilityRule.Action.ALLOW);
103 | }
104 |
105 | /**
106 | * @author Trxyy
107 | */
108 | public static class Serializer implements JsonDeserializer {
109 | public Argument deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
110 | throws JsonParseException {
111 | if (json.isJsonPrimitive())
112 | return new Argument(new String[] { json.getAsString() }, null);
113 | try {
114 | if (json.isJsonObject()) {
115 | String[] values;
116 | JsonObject obj = json.getAsJsonObject();
117 | JsonElement value = obj.get("values");
118 | if (value.isJsonPrimitive()) {
119 | values = new String[] { value.getAsString() };
120 | } else {
121 | JsonArray array = value.getAsJsonArray();
122 | values = new String[array.size()];
123 | for (int i = 0; i < array.size(); i++)
124 | values[i] = array.get(i).getAsString();
125 | }
126 | List rules = new ArrayList();
127 | if (obj.has("compatibilityRules")) {
128 | JsonArray array = obj.getAsJsonArray("compatibilityRules");
129 | for (JsonElement element : array)
130 | rules.add((CompatibilityRule) context.deserialize(element, CompatibilityRule.class));
131 | }
132 | return new Argument(values, rules);
133 | }
134 | } catch (Exception e) {
135 | if (json.isJsonObject()) {
136 | String[] values;
137 | JsonObject obj = json.getAsJsonObject();
138 | JsonElement value = obj.get("value");
139 | if (value.isJsonPrimitive()) {
140 | values = new String[] { value.getAsString() };
141 | } else {
142 | JsonArray array = value.getAsJsonArray();
143 | values = new String[array.size()];
144 | for (int i = 0; i < array.size(); i++)
145 | values[i] = array.get(i).getAsString();
146 | }
147 | List rules = new ArrayList();
148 | if (obj.has("rules")) {
149 | JsonArray array = obj.getAsJsonArray("rules");
150 | for (JsonElement element : array)
151 | rules.add((CompatibilityRule) context.deserialize(element, CompatibilityRule.class));
152 | }
153 | return new Argument(values, rules);
154 | }
155 | }
156 | throw new JsonParseException("Invalid argument, must be object or string");
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/ArgumentType.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public enum ArgumentType {
7 | JVM, GAME;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/DownloadInfo.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.net.MalformedURLException;
4 | import java.net.URI;
5 | import java.net.URISyntaxException;
6 | import java.net.URL;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class DownloadInfo {
12 | /**
13 | * the path to file
14 | */
15 | protected String path;
16 | /**
17 | * The url of the file
18 | */
19 | protected URL url;
20 | /**
21 | * The sha1 of the file
22 | */
23 | protected String sha1;
24 | /**
25 | * The size of the file
26 | */
27 | protected int size;
28 |
29 | /**
30 | * The Constructor
31 | */
32 | public DownloadInfo() {
33 | }
34 |
35 | /**
36 | * The Constructor
37 | * @param other The DownloadInfo
38 | */
39 | public DownloadInfo(DownloadInfo other) {
40 | this.path = other.path;
41 | this.url = other.url;
42 | this.sha1 = other.sha1;
43 | this.size = other.size;
44 | }
45 |
46 | /**
47 | * @return The url
48 | */
49 | public URL getUrl() {
50 | return this.url;
51 | }
52 |
53 | /**
54 | * @return The Sha1
55 | */
56 | public String getSha1() {
57 | return this.sha1;
58 | }
59 |
60 | /**
61 | * @return The path
62 | */
63 | public String getPath() {
64 | return this.path;
65 | }
66 |
67 | /**
68 | * @return The size
69 | */
70 | public int getSize() {
71 | return this.size;
72 | }
73 |
74 | /**
75 | * Convert a String to a URI
76 | * @param input The URI
77 | * @return A URI
78 | */
79 | public static URI constantURI(String input) {
80 | try {
81 | return new URI(input);
82 | } catch (URISyntaxException e) {
83 | throw new Error(e);
84 | }
85 | }
86 |
87 | /**
88 | * Convert a String to a URL
89 | * @param input The URL
90 | * @return A URL
91 | */
92 | public static URL constantURL(String input) {
93 | try {
94 | return new URL(input);
95 | } catch (MalformedURLException e) {
96 | throw new Error(e);
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/LibraryDownloadInfo.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * @author Trxyy
8 | */
9 | public class LibraryDownloadInfo {
10 | /**
11 | * The download info
12 | */
13 | private DownloadInfo artifact;
14 | /**
15 | * The natives in a Map
16 | */
17 | private Map classifiers;
18 |
19 | /**
20 | * The Constructor
21 | */
22 | public LibraryDownloadInfo() {
23 | }
24 |
25 | /**
26 | * The Constructor
27 | * @param other The LibraryDownloadInfo
28 | */
29 | public LibraryDownloadInfo(LibraryDownloadInfo other) {
30 | this.artifact = other.artifact;
31 | if (other.classifiers != null) {
32 | this.classifiers = new LinkedHashMap();
33 | for (Map.Entry entry : other.classifiers.entrySet()) {
34 | this.classifiers.put(entry.getKey(), new DownloadInfo((DownloadInfo) entry.getValue()));
35 | }
36 | }
37 | }
38 |
39 | /**
40 | * Get the download info
41 | * @param classifier The native
42 | * @return A Download Info
43 | */
44 | public DownloadInfo getDownloadInfo(String classifier) {
45 | if (classifier == null) {
46 | return this.artifact;
47 | }
48 | return (DownloadInfo) this.classifiers.get(classifier);
49 | }
50 |
51 | /**
52 | * @return The downloadInfo
53 | */
54 | public DownloadInfo getArtifact() {
55 | return artifact;
56 | }
57 |
58 | /**
59 | * Set the native
60 | * @param artifact The download info
61 | */
62 | public void setArtifact(DownloadInfo artifact) {
63 | this.artifact = artifact;
64 | }
65 |
66 | /**
67 | * @return The natives in a Map
68 | */
69 | public Map getClassifiers() {
70 | return classifiers;
71 | }
72 |
73 | /**
74 | * Set the natives
75 | * @param classifiers The natives in a Map
76 | */
77 | public void setClassifiers(Map classifiers) {
78 | this.classifiers = classifiers;
79 | }
80 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/MinecraftClient.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class MinecraftClient {
7 |
8 | /**
9 | * The client url
10 | */
11 | private DownloadInfo client;
12 |
13 | /**
14 | * @return The client
15 | */
16 | public DownloadInfo getClient() {
17 | return client;
18 | }
19 |
20 | /**
21 | * Set the Client Info
22 | * @param client The download Info
23 | */
24 | public void setClient(DownloadInfo client) {
25 | this.client = client;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/MinecraftLibrary.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.util.ArrayList;
4 | import java.util.EnumMap;
5 | import java.util.HashMap;
6 | import java.util.LinkedHashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.stream.Collectors;
10 | import java.util.stream.IntStream;
11 |
12 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.Arch;
13 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.CompatibilityRule;
14 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.OperatingSystem;
15 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.Substitutor;
16 |
17 | /**
18 | * @author Trxyy
19 | */
20 | public class MinecraftLibrary {
21 | /**
22 | * The Substitutor
23 | */
24 | private Substitutor SUBSTITUTOR = new Substitutor(new HashMap() {});
25 | /**
26 | * The library name
27 | */
28 | protected String name;
29 | /**
30 | * The Compatibility Rules
31 | */
32 | public List rules;
33 | /*
34 | * The natives in a Map
35 | */
36 | protected Map natives; // fais un bug. LibraryOS
37 | /**
38 | * The Minecraft extract rules
39 | */
40 | protected MinecraftRules extract;
41 | /**
42 | * The Library download info
43 | */
44 | protected LibraryDownloadInfo downloads;
45 | /**
46 | * The download url
47 | */
48 | private String url;
49 | /**
50 | * Is skipped ?
51 | */
52 | private boolean skipped = false;
53 |
54 | /**
55 | * The download info
56 | */
57 | private DownloadInfo artifact;
58 |
59 | /**
60 | * The natives in a Map
61 | */
62 | private Map classifiers;
63 |
64 | /**
65 | * The Constructor
66 | */
67 | public MinecraftLibrary() {
68 | }
69 |
70 | /**
71 | * The Constructor
72 | * @param name The name
73 | */
74 | public MinecraftLibrary(String name) {
75 | if ((name == null) || (name.length() == 0)) {
76 | throw new IllegalArgumentException("Library name cannot be null or empty");
77 | }
78 | this.name = name;
79 | }
80 |
81 | /**
82 | * @return If library is allowed
83 | */
84 | public boolean appliesToCurrentEnvironment() {
85 | if (this.rules == null)
86 | return true;
87 | CompatibilityRule.Action lastAction = CompatibilityRule.Action.DISALLOW;
88 |
89 | for (CompatibilityRule compatibilityRule : this.rules) {
90 | CompatibilityRule.Action action = compatibilityRule.getAppliedAction();
91 | if (action != null)
92 | lastAction = action;
93 |
94 | }
95 | return (lastAction == CompatibilityRule.Action.ALLOW);
96 | }
97 |
98 | /**
99 | * The Constructor
100 | * @param library The library
101 | */
102 | public MinecraftLibrary(MinecraftLibrary library) {
103 | HashMap map = new HashMap();
104 | map.put("platform", OperatingSystem.getCurrent().getName());
105 | map.put("arch", Arch.CURRENT.getBit());
106 | SUBSTITUTOR = new Substitutor(map);
107 |
108 | this.name = library.name;
109 | if (library.url != null) {
110 | this.url = library.url;
111 | }
112 | if (!library.url.equals("")) {
113 | this.url = library.url;
114 | }
115 | if (library.extract != null) {
116 | this.extract = new MinecraftRules(library.extract);
117 | }
118 | if (library.rules != null) {
119 | this.rules = new ArrayList();
120 | for (CompatibilityRule compatibilityRule : library.rules) {
121 | this.rules.add(new CompatibilityRule(compatibilityRule));
122 | }
123 | }
124 | if (library.natives != null) {
125 | this.natives = new LinkedHashMap();
126 | for (Map.Entry entry : library.getNatives().entrySet()) {
127 | this.natives.put(entry.getKey(), entry.getValue());
128 | }
129 | }
130 | if (library.downloads != null) {
131 | this.downloads = new LibraryDownloadInfo(library.downloads);
132 | }
133 |
134 | this.artifact = library.artifact;
135 | if (library.classifiers != null) {
136 | // this.classifiers = library.classifiers;
137 | this.classifiers = new LinkedHashMap();
138 | for (Map.Entry entry : library.classifiers.entrySet()) {
139 | this.classifiers.put(entry.getKey(), new DownloadInfo((DownloadInfo) entry.getValue()));
140 | }
141 | }
142 | }
143 |
144 | /**
145 | * Add some natives
146 | * @param operatingSystem The Operating System (Windows, Linux, Mac...)
147 | * @param name The native name
148 | * @return A MinecraftLibrary
149 | */
150 | public MinecraftLibrary addNative(OperatingSystem operatingSystem, String name) {
151 | if ((operatingSystem == null) || (!operatingSystem.isSupported())) {
152 | throw new IllegalArgumentException("Cannot add native for unsupported OS");
153 | }
154 | if ((name == null) || (name.length() == 0)) {
155 | throw new IllegalArgumentException("Cannot add native for null or empty name");
156 | }
157 | if (this.natives == null) {
158 | this.natives = new EnumMap(OperatingSystem.class);
159 | }
160 | this.natives.put(operatingSystem, name);
161 | return this;
162 | }
163 |
164 | /**
165 | * @return The Natives in a Map
166 | */
167 | public Map getNatives() {
168 | return this.natives;
169 | }
170 |
171 | /**
172 | * @return If the library has required natives
173 | */
174 | public boolean hasNatives() {
175 | return this.natives != null;
176 | }
177 |
178 | /**
179 | * @return The extract rules
180 | */
181 | public MinecraftRules getExtractRules() {
182 | return this.extract;
183 | }
184 |
185 | /**
186 | * @return The compatibility rules
187 | */
188 | public List getCompatibilityRules() {
189 | return this.rules;
190 | }
191 |
192 | /**
193 | * @return The name
194 | */
195 | public String getName() {
196 | return this.name;
197 | }
198 |
199 | /**
200 | * Set extract rules
201 | * @param rules The Minecraft Rules
202 | * @return A Minecraft Library
203 | */
204 | public MinecraftLibrary setExtractRules(MinecraftRules rules) {
205 | this.extract = rules;
206 | return this;
207 | }
208 |
209 | /**
210 | * @return The Artifact base directory
211 | */
212 | // public String getArtifactBaseDir() {
213 | // if (this.name == null) {
214 | // throw new IllegalStateException("Cannot get artifact dir of empty/blank artifact");
215 | // }
216 | // String[] parts = this.name.split(":");
217 | // return String.format("%s/%s/%s", new Object[] { parts[0].replaceAll("\\.", "/"), parts[1], parts[2] });
218 | // }
219 |
220 |
221 | private String getArtifactBaseDir() {
222 | if (this.name == null)
223 | throw new IllegalStateException("Cannot get artifact dir of empty/blank artifact");
224 | String[] parts = this.name.split(":");
225 | return String.format("%s/%s/%s", new Object[] { parts[0].replaceAll("\\.", "/"), parts[1], parts[2] });
226 | }
227 |
228 | /**
229 | * @return The artifact path
230 | */
231 | public String getArtifactPath() {
232 | return getArtifactPath(null);
233 | }
234 |
235 | /**
236 | * @param classifier The native
237 | * @return The artifact Path with native
238 | */
239 | public String getArtifactPath(String classifier) {
240 | if (this.name == null) {
241 | throw new IllegalStateException("Cannot get artifact path of empty/blank artifact");
242 | }
243 | return String.format("%s/%s", new Object[] { getArtifactBaseDir(), getArtifactFilename(classifier) });
244 | }
245 |
246 | /**
247 | * @param classifier The native
248 | * @return The Artifact File Name
249 | */
250 | public String getArtifactFilename(String classifier) {
251 | String result;
252 | if (this.name == null)
253 | throw new IllegalStateException("Cannot get artifact filename of empty/blank artifact");
254 | String[] parts = this.name.split(":");
255 | if (classifier == null) {
256 | result = (String) IntStream.range(1, parts.length).mapToObj(i -> parts[i]).collect(Collectors.joining("-")) + ".jar";
257 | } else {
258 | result = String.format("%s-%s%s.jar", new Object[] { parts[1], parts[2], "-" + classifier });
259 | }
260 | return SUBSTITUTOR.replace(result);
261 | }
262 |
263 | /**
264 | * @param libArg The library
265 | * @return The artifact natives
266 | */
267 | public String getArtifactNatives(String libArg) {
268 | String[] split = getName().split(":");
269 | String libName = split[1];
270 | String libVersion = split[2];
271 | return libName + "-" + libVersion + "-" + libArg + ".jar";
272 | }
273 |
274 | /**
275 | * @return The plain name
276 | */
277 | public String getPlainName() {
278 | String[] split = this.name.split(":");
279 | return split[0] + "." + split[1];
280 | }
281 |
282 | /**
283 | * @return If is library skipped
284 | */
285 | public boolean isSkipped() {
286 | return this.skipped;
287 | }
288 |
289 | /**
290 | * Set the library skipped or not
291 | * @param skipped
292 | */
293 | public void setSkipped(boolean skipped) {
294 | this.skipped = skipped;
295 | }
296 |
297 | /**
298 | * @return The Library download info
299 | */
300 | public LibraryDownloadInfo getDownloads() {
301 | return downloads;
302 | }
303 |
304 | /**
305 | * Set the download info
306 | * @param downloads
307 | */
308 | public void setDownloads(LibraryDownloadInfo downloads) {
309 | this.downloads = downloads;
310 | }
311 |
312 | /**
313 | * Get the download info
314 | * @param classifier The native
315 | * @return A Download Info
316 | */
317 | public DownloadInfo getDownloadInfo(String classifier) {
318 | if (classifier == null) {
319 | return this.artifact;
320 | }
321 | return (DownloadInfo) this.classifiers.get(classifier);
322 | }
323 |
324 | /**
325 | * @return The downloadInfo
326 | */
327 | public DownloadInfo getArtifact() {
328 | return artifact;
329 | }
330 |
331 | /**
332 | * Set the native
333 | * @param artifact The download info
334 | */
335 | public void setArtifact(DownloadInfo artifact) {
336 | this.artifact = artifact;
337 | }
338 |
339 | /**
340 | * @return The natives in a Map
341 | */
342 | public Map getClassifiers() {
343 | return classifiers;
344 | }
345 |
346 | /**
347 | * Set the natives
348 | * @param classifiers The natives in a Map
349 | */
350 | public void setClassifiers(Map classifiers) {
351 | this.classifiers = classifiers;
352 | }
353 |
354 | /**
355 | * toString()
356 | */
357 | public String toString() {
358 | return "Library{name='" + this.name + '\'' + ", rules=" + this.rules + ", natives=" + this.natives
359 | + ", extract=" + this.extract + '}';
360 | }
361 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/MinecraftRules.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.Iterator;
6 | import java.util.List;
7 |
8 | /**
9 | * @author Trxyy
10 | */
11 | public class MinecraftRules {
12 | /**
13 | * The excludes in a List
14 | */
15 | private List exclude = new ArrayList();
16 |
17 | /**
18 | * The Constructor
19 | */
20 | public MinecraftRules() {
21 | }
22 |
23 | /**
24 | * The Constructor
25 | * @param exclude The excludes
26 | */
27 | public MinecraftRules(String[] exclude) {
28 | if (exclude != null) {
29 | Collections.addAll(this.exclude, exclude);
30 | }
31 | }
32 |
33 | /**
34 | * The Constructor
35 | * @param rules The minecraft rules
36 | */
37 | public MinecraftRules(MinecraftRules rules) {
38 | Iterator var3 = rules.exclude.iterator();
39 | while (var3.hasNext()) {
40 | String exclude = (String) var3.next();
41 | this.exclude.add(exclude);
42 | }
43 | }
44 |
45 | /**
46 | * @return The excludes in a List
47 | */
48 | public List getExcludes() {
49 | return this.exclude;
50 | }
51 |
52 | public boolean shouldExtract(String path) {
53 | if (this.exclude == null) {
54 | return true;
55 | }
56 | Iterator var3 = this.exclude.iterator();
57 | while (var3.hasNext()) {
58 | String rule = (String) var3.next();
59 | if (path.startsWith(rule)) {
60 | return false;
61 | }
62 | }
63 | return true;
64 | }
65 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/MinecraftSave.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | public class MinecraftSave {
7 |
8 | public String minecraftArguments;
9 | public Map> arguments;
10 | public List libraries;
11 |
12 | public MinecraftSave() {
13 | }
14 |
15 | public void addMinecraftArguments(String args) {
16 | this.minecraftArguments = this.minecraftArguments + args;
17 | }
18 |
19 | public void addArguments(Map> args) {
20 | this.arguments = args;
21 | }
22 |
23 | // public void addLibraries(MinecraftLibrary libs) {
24 | // this.libraries.add(libs);
25 | // }
26 |
27 | public void addLibraries(List libs) {
28 | this.libraries = libs;
29 | }
30 |
31 | public Map> getArguments() {
32 | return this.arguments;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/MinecraftVersion.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import com.google.common.collect.Maps;
8 |
9 | import fr.trxyy.alternative.alternative_apiv2.assets.AssetIndexInfo;
10 | import fr.trxyy.alternative.alternative_apiv2.minecraft.java.JavaVersion;
11 | import fr.trxyy.alternative.alternative_apiv2.minecraft.log4j.Log4jLogging;
12 |
13 | /**
14 | * @author Trxyy
15 | */
16 | public class MinecraftVersion {
17 |
18 | /**
19 | * Forge specific comment.
20 | */
21 | private String[] _comment_;
22 | /**
23 | * The minecraft version id
24 | */
25 | private String id;
26 | /**
27 | * The inheritsFrom
28 | */
29 | private String inheritsFrom;
30 | /**
31 | * The minecraft arguments (old)
32 | */
33 | private String minecraftArguments;
34 | /**
35 | * The minecraft libraries
36 | */
37 | private List libraries;
38 | /**
39 | * The main class
40 | */
41 | private String mainClass;
42 | /**
43 | * The assets
44 | */
45 | private String assets;
46 | /**
47 | * The asset Index
48 | */
49 | private AssetIndexInfo assetIndex;
50 | /**
51 | * The required downloads
52 | */
53 | private MinecraftClient downloads;
54 | /**
55 | * The minecraft arguments (new)
56 | */
57 | public Map> arguments;
58 | /**
59 | * The minecraft java version to use
60 | */
61 | public JavaVersion javaVersion;
62 | /**
63 | * The Logging file
64 | */
65 | public Log4jLogging logging;
66 |
67 | /**
68 | * The Constructor
69 | */
70 | public MinecraftVersion() {
71 | }
72 |
73 | /**
74 | * The Constructor
75 | * @param version The MinecraftVersion
76 | */
77 | public MinecraftVersion(MinecraftVersion version) {
78 | this.id = version.id;
79 | if (version.inheritsFrom != null) {
80 | this.inheritsFrom = version.inheritsFrom;
81 | }
82 | if (version.assetIndex != null) {
83 | this.assetIndex = version.assetIndex;
84 | }
85 | if (version.arguments != null) {
86 | this.arguments = Maps.newEnumMap(ArgumentType.class);
87 | for (Map.Entry> entry : version.arguments.entrySet()) {
88 | this.arguments.put(entry.getKey(), new ArrayList(entry.getValue()));
89 | }
90 | }
91 | this.minecraftArguments = version.minecraftArguments;
92 | this.libraries = version.libraries;
93 | this.mainClass = version.mainClass;
94 | this.assets = version.assets;
95 | this.logging = version.logging;
96 | }
97 |
98 | /**
99 | * @return The Minecraft arguments (old)
100 | */
101 | public String getMinecraftArguments() {
102 | return this.minecraftArguments;
103 | }
104 |
105 | /**
106 | * @return The Minecraft libraries as a List
107 | */
108 | public List getLibraries() {
109 | return libraries;
110 | }
111 |
112 | /**
113 | * @return The Minecraft required downloads
114 | */
115 | public MinecraftClient getDownloads() {
116 | return downloads;
117 | }
118 |
119 | /**
120 | * @return The Minecraft required java version
121 | */
122 | public JavaVersion getJavaVersion() {
123 | return javaVersion;
124 | }
125 |
126 | /**
127 | * @return The Logging
128 | */
129 | public Log4jLogging getLogging() {
130 | return logging;
131 | }
132 |
133 | /**
134 | * @return The version Id
135 | */
136 | public String getId() {
137 | return id;
138 | }
139 |
140 | /**
141 | * Set the Version Id
142 | * @param idd The version id
143 | */
144 | public void setId(String idd) {
145 | this.id = idd;
146 | }
147 |
148 | /**
149 | * @return The inherits From
150 | */
151 | public String getInheritsFrom() {
152 | return inheritsFrom;
153 | }
154 |
155 | /**
156 | * Set the InheritsFrom
157 | * @param inheritsFrom The inherits from version
158 | */
159 | public void setInheritsFrom(String inheritsFrom) {
160 | this.inheritsFrom = inheritsFrom;
161 | }
162 |
163 | /**
164 | * @return The main class
165 | */
166 | public String getMainClass() {
167 | return mainClass;
168 | }
169 |
170 | /**
171 | * Set the main class
172 | * @param mainClass The main class
173 | */
174 | public void setMainClass(String mainClass) {
175 | this.mainClass = mainClass;
176 | }
177 |
178 | /**
179 | * @return The assets
180 | */
181 | public String getAssets() {
182 | return assets;
183 | }
184 |
185 | /**
186 | * Set the Assets
187 | * @param assets The assets
188 | */
189 | public void setAssets(String assets) {
190 | this.assets = assets;
191 | }
192 |
193 | /**
194 | * @return The AssetIndexInfo
195 | */
196 | public AssetIndexInfo getAssetIndex() {
197 | return assetIndex;
198 | }
199 |
200 | /**
201 | * Set the asset Index
202 | * @param s The asset Index version
203 | */
204 | public void setAssetIndex(String s) {
205 | this.assets = s;
206 | }
207 |
208 | /**
209 | * @return The arguments as a List (new)
210 | */
211 | public Map> getArguments() {
212 | return this.arguments;
213 | }
214 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/json/VersionsLister.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.json;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.ArrayList;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 |
8 | public class VersionsLister {
9 | public ArrayList versions = new ArrayList();
10 |
11 | public ArrayList getVersions() {
12 | return versions;
13 | }
14 |
15 | public Version getLastVersion() {
16 | return versions.get(0);
17 | }
18 |
19 | public class Version {
20 |
21 | public String id;
22 | public String type;
23 | public String url;
24 | public String time;
25 | public String releaseTime;
26 |
27 | public Version() {
28 | }
29 |
30 | public Version(String id_, String type_, String url_, String time_, String releaseTime_) {
31 | this.id = id_;
32 | this.type = type_;
33 | this.url = url_;
34 | this.time = time_;
35 | this.releaseTime = releaseTime_;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getType() {
43 | return type;
44 | }
45 |
46 | public String getUrl() {
47 | return url;
48 | }
49 |
50 | public String getTime() {
51 | return time;
52 | }
53 |
54 | public String getTimeSimple() {
55 | Calendar calendar = javax.xml.bind.DatatypeConverter.parseDateTime(time);
56 | Date date = calendar.getTime();
57 | SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy à HH:mm");
58 | String formatDateTime = format1.format(date);
59 | return formatDateTime;
60 | }
61 |
62 | public String getReleaseTime() {
63 | return releaseTime;
64 | }
65 |
66 | }
67 |
68 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/log4j/Log4JPatch.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.log4j;
2 |
3 | public class Log4JPatch {
4 |
5 | public static String log4j_112_116 = "https://launcher.mojang.com/v1/objects/02937d122c86ce73319ef9975b58896fc1b491d1/log4j2_112-116.xml";
6 | public static String log4j_17_111 = "https://launcher.mojang.com/v1/objects/4bb89a97a66f350bc9f73b3ca8509632682aea2e/log4j2_17-111.xml";
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/log4j/Log4jClient.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.log4j;
2 |
3 | public class Log4jClient {
4 |
5 | public String argument;
6 | public Log4jFile file;
7 | public String type;
8 |
9 | public Log4jClient() {
10 |
11 | }
12 |
13 | public Log4jClient(Log4jClient o) {
14 | this.argument = o.argument;
15 | this.file = o.file;
16 | this.type = o.type;
17 | }
18 |
19 | public String getArgument() {
20 | return argument;
21 | }
22 |
23 | public Log4jFile getFile() {
24 | return file;
25 | }
26 |
27 | public String getType() {
28 | return type;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/log4j/Log4jFile.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.log4j;
2 |
3 | public class Log4jFile {
4 |
5 | public String id;
6 | public String sha1;
7 | public int size;
8 | public String url;
9 |
10 | public Log4jFile() {
11 |
12 | }
13 |
14 | public Log4jFile(Log4jFile o) {
15 | this.id = o.id;
16 | this.sha1 = o.sha1;
17 | this.size = o.size;
18 | this.url = o.url;
19 | }
20 |
21 | public String getId() {
22 | return id;
23 | }
24 |
25 | public String getSha1() {
26 | return sha1;
27 | }
28 |
29 | public int getSize() {
30 | return size;
31 | }
32 |
33 | public String getUrl() {
34 | return url;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/log4j/Log4jLogging.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.log4j;
2 |
3 | public class Log4jLogging {
4 |
5 | public Log4jClient client;
6 |
7 | public Log4jLogging() {
8 |
9 | }
10 |
11 | public Log4jLogging(Log4jLogging o) {
12 | this.client = o.client;
13 | }
14 |
15 | public Log4jClient getClient() {
16 | return this.client;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/Arch.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public enum Arch {
7 | x86(32), x64(64), UNKNOWN(0);
8 |
9 | /**
10 | * The current Arch
11 | */
12 | public static final Arch CURRENT = getCurrent();
13 | /**
14 | * The minimum memory
15 | */
16 | public static final int MIN_MEMORY = 512;
17 | /**
18 | * The bit
19 | */
20 | private final int bit;
21 | /**
22 | * The arc
23 | */
24 | private final int arch;
25 | /**
26 | * The sBit
27 | */
28 | private final String sBit;
29 | /**
30 | * The sArch
31 | */
32 | private final String sArch;
33 |
34 | /**
35 | * The Constructor
36 | * @param bit The bit
37 | */
38 | private Arch(int bit) {
39 | this.bit = bit;
40 | this.sBit = String.valueOf(bit);
41 | if (bit == 0) {
42 | this.sArch = toString();
43 | this.arch = 0;
44 | } else {
45 | this.sArch = toString().substring(1);
46 | this.arch = Integer.parseInt(this.sArch);
47 | }
48 | }
49 |
50 | /**
51 | * @return Get the sBit
52 | */
53 | public String getBit() {
54 | return this.sBit;
55 | }
56 |
57 | /**
58 | * @return is Current
59 | */
60 | public boolean isCurrent() {
61 | return this == CURRENT;
62 | }
63 |
64 | /**
65 | * @return The current Arch
66 | */
67 | private static Arch getCurrent() {
68 | String curArch = System.getProperty("sun.arch.data.model");
69 | Arch[] var4;
70 | int var3 = (var4 = values()).length;
71 | for (int var2 = 0; var2 < var3; var2++) {
72 | Arch arch = var4[var2];
73 | if (arch.sBit.equals(curArch)) {
74 | return arch;
75 | }
76 | }
77 | return UNKNOWN;
78 | }
79 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/CompatibilityRule.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * @author Trxyy
7 | */
8 | public class CompatibilityRule {
9 | /**
10 | * The Action
11 | */
12 | private Action action;
13 | /**
14 | * The os restriction
15 | */
16 | private OSRestriction os;
17 | /**
18 | * The features as a Map
19 | */
20 | private Map features;
21 |
22 | /**
23 | * The Constructor
24 | */
25 | public CompatibilityRule() {
26 | this.setAction(Action.ALLOW);
27 | }
28 |
29 | /**
30 | * The Constructor
31 | * @param rule The rules
32 | */
33 | public CompatibilityRule(CompatibilityRule rule) {
34 | this.setAction(Action.ALLOW);
35 | this.setAction(rule.getAction());
36 | if (rule.os != null) {
37 | this.setOs(new OSRestriction(rule.getOs()));
38 | }
39 | if (rule.features != null) {
40 | this.features = rule.features;
41 | }
42 | }
43 |
44 | /**
45 | * toString()
46 | */
47 | public String toString() {
48 | return "Rule{action=" + this.getAction() + ", os=" + this.getOs() + '}';
49 | }
50 |
51 | /**
52 | * @return The OS restriction
53 | */
54 | public OSRestriction getOs() {
55 | return os;
56 | }
57 |
58 | /**
59 | * Set the OS
60 | * @param os The OS restriction
61 | */
62 | public void setOs(OSRestriction os) {
63 | this.os = os;
64 | }
65 |
66 | /**
67 | * @return The Action
68 | */
69 | public Action getAction() {
70 | return action;
71 | }
72 |
73 | /**
74 | * Set the Action
75 | * @param action The action
76 | */
77 | public void setAction(Action action) {
78 | this.action = action;
79 | }
80 |
81 | /**
82 | * @author Trxyy
83 | */
84 | public enum Action {
85 | ALLOW("allow", 0), DISALLOW("disallow", 1);
86 |
87 | String name;
88 |
89 | /**
90 | * The Action
91 | * @param s The name
92 | * @param n The number
93 | */
94 | private Action(final String s, final int n) {
95 | this.name = s;
96 | }
97 |
98 | public String getName() {
99 | return this.name;
100 | }
101 | }
102 |
103 | /**
104 | * @author Trxyy
105 | */
106 | public static interface FeatureMatcher {
107 | boolean hasFeature(String param1String, Object param1Object);
108 | }
109 |
110 | /**
111 | * @return The supplied Action
112 | */
113 | public Action getAppliedAction() {
114 | if ((this.os != null) && (!this.os.isCurrentOperatingSystem())) {
115 | return null;
116 | }
117 | return this.action;
118 | }
119 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/DateTypeAdapter.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.lang.reflect.Type;
4 | import java.text.DateFormat;
5 | import java.text.ParseException;
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 | import java.util.Locale;
9 |
10 | import com.google.gson.JsonDeserializationContext;
11 | import com.google.gson.JsonDeserializer;
12 | import com.google.gson.JsonElement;
13 | import com.google.gson.JsonParseException;
14 | import com.google.gson.JsonPrimitive;
15 | import com.google.gson.JsonSerializationContext;
16 | import com.google.gson.JsonSerializer;
17 | import com.google.gson.JsonSyntaxException;
18 |
19 | public class DateTypeAdapter implements JsonSerializer, JsonDeserializer {
20 |
21 | private final DateFormat enUsFormat;
22 | private final DateFormat iso8601Format;
23 |
24 | public DateTypeAdapter() {
25 | this.enUsFormat = DateFormat.getDateTimeInstance(2, 2, Locale.US);
26 | this.iso8601Format = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ssZ");
27 | }
28 |
29 | public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
30 | throws JsonParseException {
31 | if (!(json instanceof JsonPrimitive)) {
32 | throw new JsonParseException("The date should be a string value");
33 | } else {
34 | Date date = this.deserializeToDate(json.getAsString());
35 | if (typeOfT == Date.class) {
36 | return date;
37 | } else {
38 | throw new IllegalArgumentException(this.getClass() + " cannot deserialize to " + typeOfT);
39 | }
40 | }
41 | }
42 |
43 | public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
44 | DateFormat var4 = this.enUsFormat;
45 | synchronized (this.enUsFormat) {
46 | return new JsonPrimitive(this.serializeToString(src));
47 | }
48 | }
49 |
50 | public Date deserializeToDate(String string) {
51 | DateFormat var2 = this.enUsFormat;
52 | synchronized (this.enUsFormat) {
53 | Date var10000;
54 | try {
55 | var10000 = this.enUsFormat.parse(string);
56 | } catch (ParseException var7) {
57 | try {
58 | var10000 = this.iso8601Format.parse(string);
59 | } catch (ParseException var6) {
60 | try {
61 | String e = string.replace("Z", "+00:00");
62 | e = e.substring(0, 22) + e.substring(23);
63 | var10000 = this.iso8601Format.parse(e);
64 | } catch (Exception var5) {
65 | throw new JsonSyntaxException("Invalid date: " + string, var5);
66 | }
67 |
68 | return var10000;
69 | }
70 |
71 | return var10000;
72 | }
73 |
74 | return var10000;
75 | }
76 | }
77 |
78 | public String serializeToString(Date date) {
79 | DateFormat var2 = this.enUsFormat;
80 | synchronized (this.enUsFormat) {
81 | String result = this.iso8601Format.format(date);
82 | return result.substring(0, 22) + ":" + result.substring(22);
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/Duplicator.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 |
10 | /**
11 | * @author Trxyy
12 | */
13 | public class Duplicator extends Thread {
14 | /**
15 | * The source file
16 | */
17 | private File source;
18 | /**
19 | * The destination file
20 | */
21 | private File dest;
22 |
23 | /**
24 | * The Constructor
25 | * @param source The source file
26 | * @param dest The destination file
27 | */
28 | public Duplicator(File source, File dest) {
29 | this.source = source;
30 | this.dest = dest;
31 | }
32 |
33 | /**
34 | * Run the Thread
35 | */
36 | public void run() {
37 | try {
38 | startCloning();
39 | } catch (IOException e) {
40 | e.printStackTrace();
41 | }
42 | }
43 |
44 | /**
45 | * Start Cloning the file in question
46 | * @throws IOException
47 | */
48 | private void startCloning() throws IOException {
49 | InputStream input = null;
50 | OutputStream output = null;
51 | try {
52 | input = new FileInputStream(this.source);
53 | output = new FileOutputStream(this.dest);
54 | byte[] buf = new byte[1024];
55 | int bytesRead;
56 | while ((bytesRead = input.read(buf)) > 0) {
57 | output.write(buf, 0, bytesRead);
58 | }
59 | } finally {
60 | input.close();
61 | output.close();
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/EnumJavaFileType.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | public enum EnumJavaFileType {
4 | FILE("file"),
5 | DIRECTORY("directory");
6 |
7 | private String name;
8 |
9 | EnumJavaFileType(String par1Name) {
10 | this.name = par1Name;
11 | }
12 |
13 | public String getName() {
14 | return this.name;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/FileUtil.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.BufferedOutputStream;
5 | import java.io.Closeable;
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.FileOutputStream;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.OutputStream;
12 | import java.math.BigInteger;
13 | import java.net.URL;
14 | import java.nio.charset.Charset;
15 | import java.nio.file.DirectoryNotEmptyException;
16 | import java.nio.file.Files;
17 | import java.nio.file.NoSuchFileException;
18 | import java.nio.file.Path;
19 | import java.nio.file.Paths;
20 | import java.security.DigestInputStream;
21 | import java.security.MessageDigest;
22 | import java.util.Enumeration;
23 | import java.util.Scanner;
24 | import java.util.zip.ZipEntry;
25 | import java.util.zip.ZipFile;
26 |
27 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
28 | import fr.trxyy.alternative.alternative_apiv2.base.GameFolder;
29 |
30 |
31 | /**
32 | * @author Trxyy
33 | */
34 | public class FileUtil {
35 |
36 | public static GameFolder workDir;
37 |
38 | /**
39 | * Skip folders in extractions
40 | */
41 | public static String skipFoldersInExtraction = "META-INF/";
42 |
43 | /**
44 | * Delete fake natives
45 | * @param targetDir The target directory to delete files
46 | * @param engine The GameEngine instance
47 | * @throws IOException
48 | */
49 | // public static void deleteFakeNatives(File targetDir) throws IOException {
50 | // File[] listOfFiles = workDir.getNativesDir().listFiles();
51 | // for (int index = 0; index < listOfFiles.length; index++) {
52 | // if (listOfFiles[index].isFile()) {
53 | // if (!listOfFiles[index].getName().endsWith(".dll")) {
54 | // if (!listOfFiles[index].getName().endsWith(".dylib")) {
55 | // if (!listOfFiles[index].getName().endsWith(".so")) {
56 | // listOfFiles[index].delete();
57 | // }
58 | // }
59 | // }
60 | // } else {
61 | // deleteFolder(listOfFiles[index]);
62 | // }
63 | // }
64 | // }
65 |
66 | /**
67 | * Unpack natives in a designed folder
68 | * @param targetDir The target directory
69 | * @param engine
70 | * @param engine The GameEngine instance
71 | * @throws IOException
72 | */
73 | public static void unpackNatives(File targetDir, GameEngine engine) throws IOException {
74 | workDir = engine.getGameFolder();
75 | if (workDir.getNativesCacheDir().exists()) {
76 | File[] listOfFiles = workDir.getNativesCacheDir().listFiles();
77 | for (int index = 0; index < listOfFiles.length; index++) {
78 | if (listOfFiles[index].isFile()) {
79 | ZipFile zip = new ZipFile(listOfFiles[index]);
80 | try {
81 | Enumeration extends ZipEntry> entries = zip.entries();
82 | while (entries.hasMoreElements()) {
83 | ZipEntry entry = (ZipEntry) entries.nextElement();
84 | File targetFile = new File(targetDir, entry.getName());
85 | if (targetFile.getParentFile() != null) {
86 | targetFile.getParentFile().mkdirs();
87 | }
88 | if (!entry.isDirectory()) {
89 | BufferedInputStream inputStream = new BufferedInputStream(zip.getInputStream(entry));
90 |
91 | byte[] buffer = new byte[2048];
92 | FileOutputStream outputStream = new FileOutputStream(targetFile);
93 | BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
94 | try {
95 | int length;
96 | while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
97 | bufferedOutputStream.write(buffer, 0, length);
98 | }
99 | } finally {
100 | closeSilently(bufferedOutputStream);
101 | closeSilently(outputStream);
102 | closeSilently(inputStream);
103 | }
104 | }
105 | }
106 | } finally {
107 | zip.close();
108 | }
109 | }
110 | }
111 | }
112 | }
113 |
114 | /**
115 | * Force delete on exit
116 | * @param file The file in question
117 | * @throws IOException
118 | */
119 | public static void forceDeleteOnExit(File file) throws IOException {
120 | if (file.isDirectory()) {
121 | deleteDirectoryOnExit(file);
122 | } else {
123 | file.deleteOnExit();
124 | }
125 | }
126 |
127 | /**
128 | * Delete a directory on exit
129 | * @param directory The directory in question
130 | * @throws IOException
131 | */
132 | private static void deleteDirectoryOnExit(File directory) throws IOException {
133 | if (!directory.exists()) {
134 | return;
135 | }
136 | directory.deleteOnExit();
137 | if (!isSymlink(directory)) {
138 | cleanDirectoryOnExit(directory);
139 | }
140 | }
141 |
142 | /**
143 | *
144 | * @param file The File
145 | * @return
146 | * @throws IOException
147 | */
148 | public static boolean isSymlink(File file) throws IOException {
149 | if (file == null) {
150 | throw new NullPointerException("File must not be null");
151 | }
152 | char WINDOWS_SEPARATOR = '\\';
153 | if (File.separatorChar == WINDOWS_SEPARATOR) {
154 | return false;
155 | }
156 | File fileInCanonicalDir = null;
157 | if (file.getParent() == null) {
158 | fileInCanonicalDir = file;
159 | } else {
160 | File canonicalDir = file.getParentFile().getCanonicalFile();
161 | fileInCanonicalDir = new File(canonicalDir, file.getName());
162 | }
163 | if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())) {
164 | return false;
165 | }
166 | return true;
167 | }
168 |
169 | /**
170 | * Clean a directory on exit
171 | * @param directory The directory to clean
172 | * @throws IOException
173 | */
174 | public static void cleanDirectoryOnExit(File directory) throws IOException {
175 | if (!directory.exists()) {
176 | String message = directory + " does not exist";
177 | throw new IllegalArgumentException(message);
178 | }
179 | if (!directory.isDirectory()) {
180 | String message = directory + " is not a directory";
181 | throw new IllegalArgumentException(message);
182 | }
183 | File[] files = directory.listFiles();
184 | if (files == null) {
185 | throw new IOException("Failed to list contents of " + directory);
186 | }
187 | IOException exception = null;
188 | for (File file : files) {
189 | try {
190 | forceDeleteOnExit(file);
191 | } catch (IOException ioe) {
192 | exception = ioe;
193 | }
194 | }
195 | if (null != exception) {
196 | throw exception;
197 | }
198 | }
199 |
200 | /**
201 | * @return The Charset
202 | */
203 | public static Charset getCharset() {
204 | try {
205 | return Charset.forName("UTF-8");
206 | } catch (Exception var1) {
207 | throw new Error("UTF-8 is not supported", var1);
208 | }
209 | }
210 |
211 | /**
212 | * @param file The file
213 | * @param algorithm The algorithm to use
214 | * @param hashLength The hash lenght
215 | * @return A new String
216 | */
217 | public static String getDigest(File file, String algorithm, int hashLength) {
218 | DigestInputStream stream = null;
219 | try {
220 | stream = new DigestInputStream(new FileInputStream(file), MessageDigest.getInstance(algorithm));
221 | byte[] ignored = new byte[65536];
222 | int read;
223 | do {
224 | read = stream.read(ignored);
225 | } while (read > 0);
226 | return String.format("%1$0" + hashLength + "x",
227 | new Object[] { new BigInteger(1, stream.getMessageDigest().digest()) });
228 | } catch (Exception localException) {
229 | } finally {
230 | close(stream);
231 | }
232 | return null;
233 | }
234 |
235 | /**
236 | * Close
237 | * @param a The Closeable
238 | */
239 | private static void close(Closeable a) {
240 | try {
241 | a.close();
242 | } catch (Exception var2) {
243 | var2.printStackTrace();
244 | }
245 | }
246 |
247 | public static String getSHA(File file) {
248 | return getDigest(file, "SHA", 40);
249 | }
250 |
251 | /**
252 | * @param file The File
253 | * @param sha1 The Sha1
254 | * @return True if the file Md5 Match with the Sha1 String
255 | */
256 | public static boolean matchSHA1(final File file, final String sha1) {
257 | try {
258 | return getSHA(file).equals(sha1);
259 | } catch (Exception e) {
260 | e.printStackTrace();
261 | return false;
262 | }
263 | }
264 |
265 | /**
266 | * Close silently
267 | * @param closeable The Closeable
268 | */
269 | public static void closeSilently(Closeable closeable) {
270 | if (closeable != null) {
271 | try {
272 | closeable.close();
273 | } catch (IOException localIOException) {
274 | }
275 | }
276 | }
277 |
278 | /**
279 | * Copy a file from mc directory to our directory
280 | * @param mc The mc folder
281 | * @param local The directory in question
282 | * @throws IOException
283 | */
284 | public static void copy(File mc, File local) throws IOException {
285 | InputStream input = null;
286 | OutputStream output = null;
287 | try {
288 | input = new FileInputStream(mc);
289 | output = new FileOutputStream(local);
290 | byte[] buf = new byte[1024];
291 | int bytesRead;
292 | while ((bytesRead = input.read(buf)) > 0) {
293 | output.write(buf, 0, bytesRead);
294 | }
295 | } finally {
296 | input.close();
297 | output.close();
298 | }
299 | }
300 |
301 | /**
302 | * Delete a folder
303 | * @param folder The folder in question
304 | */
305 | public static void deleteFolder(File folder) {
306 | File[] files = folder.listFiles();
307 | if (files != null) { // some JVMs return null for empty dirs
308 | for (File f : files) {
309 | if (f.isDirectory()) {
310 | deleteFolder(f);
311 | } else {
312 | f.delete();
313 | }
314 | }
315 | }
316 | folder.delete();
317 | }
318 |
319 | /**
320 | * Delete something
321 | * @param path The pathto the file to delete
322 | */
323 | public static void deleteSomething(String path) {
324 | Path filePath_1 = Paths.get(path);
325 | try {
326 | Files.delete(filePath_1);
327 | } catch (NoSuchFileException x) {
328 | System.err.format("%s: no such" + " file or directory%n", path);
329 | } catch (DirectoryNotEmptyException x) {
330 | System.err.format("%s not empty%n", path);
331 | } catch (IOException x) {
332 | System.err.println(x);
333 | }
334 | }
335 |
336 | /**
337 | * @param etag The etag
338 | * @return The etag as a String
339 | */
340 | public static String getEtag(String etag) {
341 | if (etag == null)
342 | etag = "-";
343 | else if (etag.startsWith("\"") && etag.endsWith("\""))
344 | etag = etag.substring(1, etag.length() - 1);
345 |
346 | return etag;
347 | }
348 |
349 | /**
350 | * @param file The file to get the MD5
351 | * @return The MD5 as a String
352 | */
353 | public static String getMD5(final File file) {
354 | DigestInputStream stream = null;
355 | try {
356 | stream = new DigestInputStream(new FileInputStream(file), MessageDigest.getInstance("MD5"));
357 | final byte[] buffer = new byte[65536];
358 |
359 | int read = stream.read(buffer);
360 | while (read >= 1)
361 | read = stream.read(buffer);
362 | } catch (final Exception ignored) {
363 | return null;
364 | } finally {
365 | closeSilently(stream);
366 | }
367 |
368 | return String.format("%1$032x", new Object[] { new BigInteger(1, stream.getMessageDigest().digest()) });
369 | }
370 |
371 | /**
372 | * @param url The URL to read
373 | * @return The result of the url
374 | */
375 | public static String readMD5(String url) {
376 | String result = "";
377 | try {
378 | Scanner scan = new Scanner((new URL(url)).openStream(), "UTF-8");
379 | if (!scan.hasNextLine()) {
380 | scan.close();
381 | }
382 | result = scan.nextLine();
383 | scan.close();
384 | return result;
385 | } catch (IOException e) {
386 | e.printStackTrace();
387 | }
388 | return result;
389 | }
390 | }
391 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/GameUtils.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
8 | import fr.trxyy.alternative.alternative_apiv2.base.GameFolder;
9 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.MinecraftLibrary;
10 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.MinecraftVersion;
11 |
12 | /**
13 | * @author Trxyy
14 | */
15 | public class GameUtils {
16 |
17 | /**
18 | * @param workDir The working directory
19 | * @return The working directory fro each OS
20 | */
21 | public static File getWorkingDirectory(String workDir) {
22 | String userHome = System.getProperty("user.home", ".");
23 | File workingDirectory;
24 | switch (getPlatform()) {
25 | case 1:
26 | workingDirectory = new File(userHome + "/." + workDir);
27 | case 2:
28 | workingDirectory = new File(userHome + "/." + workDir);
29 | break;
30 | case 3:
31 | workingDirectory = new File(userHome + "\\AppData\\Roaming\\." + workDir);
32 | break;
33 | case 4:
34 | workingDirectory = new File(userHome + "/Library/Application Support/" + workDir);
35 | break;
36 | default:
37 | workingDirectory = new File(userHome + "/." + workDir);
38 | }
39 | return workingDirectory;
40 | }
41 |
42 | /**
43 | * @return The current Platform
44 | */
45 | private static int getPlatform() {
46 | String osName = System.getProperty("os.name").toLowerCase();
47 | if (osName.contains("linux"))
48 | return 1;
49 | if (osName.contains("unix"))
50 | return 1;
51 | if (osName.contains("solaris"))
52 | return 2;
53 | if (osName.contains("sunos"))
54 | return 2;
55 | if (osName.contains("win"))
56 | return 3;
57 | if (osName.contains("mac"))
58 | return 4;
59 | return 5;
60 | }
61 |
62 | /**
63 | * @param mcVersion The GameEngine instance
64 | * @return A String that contains the classpath
65 | */
66 | public static String constructClasspath(MinecraftVersion mcVersion, GameEngine engine) {
67 | GameFolder workDir = engine.getGameFolder();
68 | String result = "";
69 | List test = mcVersion.getLibraries();
70 | ArrayList libs = getMinecraftLibraries(mcVersion, engine);
71 | String separator = System.getProperty("path.separator");
72 | for (File lib : libs) {
73 | // if (lib.getAbsolutePath().contains("fmlloader")) {
74 | //
75 | // }
76 | if (lib.getAbsolutePath().contains("-srg")) {
77 |
78 | }
79 | else if (lib.getAbsolutePath().contains("-extra")) {
80 |
81 | }
82 | else if (lib.getAbsolutePath().contains("fmlcore")) {
83 |
84 | }
85 | else if (lib.getAbsolutePath().contains("javafmllanguage")) {
86 |
87 | }
88 | else if (lib.getAbsolutePath().contains("mclanguage")) {
89 |
90 | }
91 | else if (lib.getAbsolutePath().contains("-universal")) {
92 |
93 | } else {
94 | result += lib.getAbsolutePath() + separator;
95 | }
96 |
97 | // if (!lib.getAbsolutePath().contains("fmlloader") ||
98 | // !lib.getAbsolutePath().contains("-srg") ||
99 | // !lib.getAbsolutePath().contains("-extra") ||
100 | // !lib.getAbsolutePath().contains("fmlcore") ||
101 | // !lib.getAbsolutePath().contains("javafmllanguage") ||
102 | // !lib.getAbsolutePath().contains("mclanguage") ||
103 | // !lib.getAbsolutePath().contains("-universal")) {
104 | // result += lib.getAbsolutePath() + separator;
105 | // }
106 | }
107 | File versionFolder = new File(workDir.getVersionsDir(), mcVersion.getId());
108 | result += new File(versionFolder, mcVersion.getId() + ".jar").getAbsolutePath();
109 | return result;
110 | }
111 |
112 | private static ArrayList getMinecraftLibraries(MinecraftVersion minecraftVersion, GameEngine engine) {
113 | ArrayList theLibraries = new ArrayList();
114 | GameFolder workDir = engine.getGameFolder();
115 | for (MinecraftLibrary lib : minecraftVersion.getLibraries()) {
116 | if (lib.appliesToCurrentEnvironment()) {
117 | File libPath = new File(workDir.getLibsDir(), lib.getArtifactPath());
118 | theLibraries.add(libPath);
119 | }
120 | }
121 | return theLibraries;
122 | }
123 |
124 | /**
125 | * @param folder The folder to list
126 | * @return A ArrayList that contains all files listed
127 | */
128 | public static ArrayList list(File folder) {
129 | ArrayList files = new ArrayList();
130 | if (!folder.isDirectory())
131 | return files;
132 |
133 | File[] folderFiles = folder.listFiles();
134 | if (folderFiles != null)
135 | for (File f : folderFiles)
136 | if (f.isDirectory())
137 | files.addAll(list(f));
138 | else
139 | files.add(f);
140 |
141 | return files;
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/JsonUtil.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStreamReader;
7 | import java.net.URL;
8 | import java.util.Date;
9 |
10 | import com.google.gson.Gson;
11 | import com.google.gson.GsonBuilder;
12 |
13 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.Argument;
14 |
15 | public class JsonUtil {
16 |
17 | public static Gson getGson() {
18 | final GsonBuilder gsonBuilder = new GsonBuilder();
19 | gsonBuilder.registerTypeAdapterFactory(new LowerCaseEnumTypeAdapterFactory());
20 | gsonBuilder.registerTypeAdapter(Date.class, new DateTypeAdapter());
21 | gsonBuilder.registerTypeAdapter(Argument.class, new Argument.Serializer());
22 | gsonBuilder.enableComplexMapKeySerialization();
23 | gsonBuilder.setPrettyPrinting();
24 | return gsonBuilder.create();
25 | }
26 |
27 | public static String loadJSON(String inUrl) throws IOException {
28 | URL url = new URL(inUrl);
29 | BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
30 | String json = new String();
31 | String inputLine;
32 | while ((inputLine = in.readLine()) != null) {
33 | json = json + inputLine;
34 | }
35 | return json;
36 | }
37 |
38 | public static String loadJSONFile(File inUrl) throws IOException {
39 | URL url = new URL(inUrl.toURI().toString());
40 | BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
41 | String json = new String();
42 | String inputLine;
43 | while ((inputLine = in.readLine()) != null) {
44 | json = json + inputLine;
45 | }
46 | return json;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/LowerCaseEnumTypeAdapterFactory.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.IOException;
4 | import java.util.HashMap;
5 | import java.util.Locale;
6 |
7 | import com.google.gson.Gson;
8 | import com.google.gson.TypeAdapter;
9 | import com.google.gson.TypeAdapterFactory;
10 | import com.google.gson.reflect.TypeToken;
11 | import com.google.gson.stream.JsonReader;
12 | import com.google.gson.stream.JsonToken;
13 | import com.google.gson.stream.JsonWriter;
14 |
15 | public class LowerCaseEnumTypeAdapterFactory implements TypeAdapterFactory {
16 |
17 | public TypeAdapter create(Gson gson, TypeToken type) {
18 | Class rawType = type.getRawType();
19 | if (!rawType.isEnum()) {
20 | return null;
21 | } else {
22 | final HashMap lowercaseToConstant = new HashMap();
23 | Object[] arr$ = rawType.getEnumConstants();
24 | int len$ = arr$.length;
25 |
26 | for (int i$ = 0; i$ < len$; ++i$) {
27 | Object constant = arr$[i$];
28 | lowercaseToConstant.put(this.toLowercase(constant), constant);
29 | }
30 |
31 | return new TypeAdapter() {
32 | public void write(JsonWriter out, Object value) throws IOException {
33 | if (value == null) {
34 | out.nullValue();
35 | } else {
36 | out.value(LowerCaseEnumTypeAdapterFactory.this.toLowercase(value));
37 | }
38 |
39 | }
40 |
41 | public Object read(JsonReader reader) throws IOException {
42 | if (reader.peek() == JsonToken.NULL) {
43 | reader.nextNull();
44 | return null;
45 | } else {
46 | return lowercaseToConstant.get(reader.nextString());
47 | }
48 | }
49 | };
50 | }
51 | }
52 |
53 | private String toLowercase(Object o) {
54 | return o.toString().toLowerCase(Locale.US);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/OSRestriction.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * @author Trxyy
8 | */
9 | public class OSRestriction {
10 | /**
11 | * The OS name
12 | */
13 | private OperatingSystem name;
14 | /**
15 | * The version
16 | */
17 | private String version;
18 |
19 | /**
20 | * The arch
21 | */
22 | private String arch;
23 |
24 | /**
25 | * @return The OS Name
26 | */
27 | public OperatingSystem getName() {
28 | return this.name;
29 | }
30 |
31 | /**
32 | * The Constructor
33 | */
34 | public OSRestriction() {
35 | }
36 |
37 | /**
38 | * @return The version
39 | */
40 | public String getVersion() {
41 | return this.version;
42 | }
43 |
44 | /**
45 | * @return The OS Arch
46 | */
47 | public String getArch() {
48 | return this.arch;
49 | }
50 |
51 | /**
52 | * The Constructor
53 | * @param osRestriction The Os restriction
54 | */
55 | public OSRestriction(OSRestriction osRestriction) {
56 | this.name = osRestriction.name;
57 | this.version = osRestriction.version;
58 | this.arch = osRestriction.arch;
59 | }
60 |
61 | /**
62 | * @return If the name is equals to the current OS
63 | */
64 | public boolean isCurrentOperatingSystem() {
65 | if (this.name != null && this.name != OperatingSystem.getCurrentPlatform())
66 | return false;
67 |
68 | if (this.version != null) {
69 | try {
70 | Pattern pattern = Pattern.compile(this.version);
71 | Matcher matcher = pattern.matcher(System.getProperty("os.version"));
72 | if (!matcher.matches())
73 | return false;
74 | } catch (Throwable throwable) {
75 | }
76 | }
77 |
78 | if (this.arch != null) {
79 | try {
80 | Pattern pattern = Pattern.compile(this.arch);
81 | Matcher matcher = pattern.matcher(System.getProperty("os.arch"));
82 | if (!matcher.matches())
83 | return false;
84 | } catch (Throwable throwable) {
85 | }
86 | }
87 |
88 | return true;
89 | }
90 |
91 | /**
92 | * toString()
93 | */
94 | public String toString() {
95 | return "OSRestriction{name=" + this.name + ", version='" + this.version + '\'' + ", arch='" + this.arch + '\''
96 | + '}';
97 | }
98 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/OperatingSystem.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.io.File;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
8 | import fr.trxyy.alternative.alternative_apiv2.base.GameFolder;
9 | import fr.trxyy.alternative.alternative_apiv2.minecraft.json.MinecraftVersion;
10 |
11 | /**
12 | * @author Trxyy
13 | */
14 | public enum OperatingSystem {
15 |
16 | LINUX(new String[] { "linux", "unix" }),
17 | WINDOWS(new String[] { "win", "windows" }),
18 | OSX(new String[] { "mac" }),
19 | SOLARIS(new String[] { "solaris", "sunos" }),
20 | UNKNOWN(new String[] { "unknown" });
21 |
22 | /**
23 | * The OS Name in System Properties
24 | */
25 | public static final String NAME = System.getProperty("os.name");
26 | /**
27 | * The name
28 | */
29 | private final String name;
30 | /**
31 | * The Os Aliases
32 | */
33 | private final String[] aliases;
34 |
35 | /**
36 | * The Constructor
37 | * @param aliases The os aliases
38 | */
39 | private OperatingSystem(String... aliases) {
40 | if (aliases == null) {
41 | throw new NullPointerException();
42 | }
43 | this.name = toString().toLowerCase();
44 | this.aliases = aliases;
45 | }
46 |
47 | /**
48 | * @return The name
49 | */
50 | public String getName() {
51 | return this.name;
52 | }
53 |
54 | /**
55 | * @return The aliases as a String[]
56 | */
57 | public String[] getAliases() {
58 | return this.aliases;
59 | }
60 |
61 | /**
62 | * @return If is supported OS
63 | */
64 | public boolean isSupported() {
65 | return this != OperatingSystem.UNKNOWN;
66 | }
67 |
68 | /**
69 | * @return If is unsupported OS
70 | */
71 | public boolean isUnsupported() {
72 | return this == UNKNOWN;
73 | }
74 |
75 | /**
76 | * @return The Java Path
77 | */
78 | public static String getJavaPath() {
79 | if (System.getProperty("os.name").toLowerCase().contains("win"))
80 | return "\"" + System.getProperty("java.home") + "\\bin\\java" + "\"";
81 |
82 | return System.getProperty("java.home") + "/bin/java";
83 | }
84 |
85 | /**
86 | * @return The Java Path Installed
87 | */
88 | public static String getJavaPath(MinecraftVersion mcVersion, GameEngine engine) {
89 | String component = mcVersion.getJavaVersion().getComponent();
90 | GameFolder workDir = engine.getGameFolder();
91 | File javaPath = new File(workDir.getRuntimeDir(), component);
92 | if (getCurrentPlatform() == OperatingSystem.WINDOWS && new File(javaPath + "/bin/javaw.exe").isFile()) {
93 | return javaPath + "/bin/javaw.exe";
94 | }
95 | return javaPath + "/bin/java";
96 | }
97 |
98 | /**
99 | * @return The Java directory
100 | */
101 | public String getJavaDir() {
102 | final String separator = System.getProperty("file.separator");
103 | final String path = System.getProperty("java.home") + separator + "bin" + separator;
104 | if (getCurrentPlatform() == OperatingSystem.WINDOWS && new File(path + "javaw.exe").isFile()) {
105 | return path + "javaw.exe";
106 | }
107 | return path + "java";
108 | }
109 |
110 | /**
111 | * @return The current Platform
112 | */
113 | public static OperatingSystem getCurrentPlatform() {
114 | final String osName = System.getProperty("os.name").toLowerCase();
115 | for (final OperatingSystem os : values()) {
116 | for (final String alias : os.getAliases()) {
117 | if (osName.contains(alias)) {
118 | return os;
119 | }
120 | }
121 | }
122 | return OperatingSystem.UNKNOWN;
123 | }
124 |
125 | /**
126 | * Is this OS match with the part
127 | * @param part The Part to match
128 | * @return If it match
129 | */
130 | public static boolean match(String part) {
131 | if (part.contains(getCurrentPlatform().getName())) {
132 | return true;
133 | }
134 | List aliases = Arrays.asList(getCurrentPlatform().getAliases());
135 | for (String alias : aliases) {
136 | if (part.contains(alias)) {
137 | return true;
138 | }
139 | }
140 | return false;
141 | }
142 |
143 | /**
144 | * @return The current Platform
145 | */
146 | public static OperatingSystem getCurrent() {
147 | String osName = NAME.toLowerCase();
148 | OperatingSystem[] var4;
149 | int var3 = (var4 = values()).length;
150 | for (int var2 = 0; var2 < var3; var2++) {
151 | OperatingSystem os = var4[var2];
152 | String[] var8 = os.aliases;
153 | int var7 = os.aliases.length;
154 | for (int var6 = 0; var6 < var7; var6++) {
155 | String alias = var8[var6];
156 | if (osName.contains(alias)) {
157 | return os;
158 | }
159 | }
160 | }
161 | return UNKNOWN;
162 | }
163 |
164 | public static String getCurrentNativesForOs(String nativeName) {
165 | final String osName = System.getProperty("os.name").toLowerCase();
166 | if (nativeName.contains(osName)) {
167 |
168 | }
169 | return "natives-windows";
170 | }
171 |
172 | // /**
173 | // * Open a link
174 | // * @param link The Url to open
175 | // */
176 | // public static void openLink(final URI link) {
177 | // try {
178 | // final Class> desktopClass = Class.forName("java.awt.Desktop");
179 | // final Object o = desktopClass.getMethod("getDesktop", (Class[]) new Class[0]).invoke(null, new Object[0]);
180 | // desktopClass.getMethod("browse", URI.class).invoke(o, link);
181 | // } catch (Throwable e2) {
182 | // if (getCurrentPlatform() == OperatingSystem.OSX) {
183 | // try {
184 | // Runtime.getRuntime().exec(new String[] { "/usr/bin/open", link.toString() });
185 | // } catch (IOException e1) {
186 | // Logger.log("Failed to open link " + link.toString());
187 | // }
188 | // } else {
189 | // Logger.log("Failed to open link " + link.toString());
190 | // }
191 | // }
192 | // }
193 |
194 | /**
195 | * Get the Java Bit
196 | */
197 | public static Arch getJavaBit() {
198 | String res = System.getProperty("sun.arch.data.model");
199 | if (res != null && res.equalsIgnoreCase("64"))
200 | return Arch.x64;
201 | return Arch.x86;
202 | }
203 |
204 | // /**
205 | // * Open a folder
206 | // * @param path The Folder Path
207 | // */
208 | // public static void openFolder(final File path) {
209 | // final String absolutePath = path.getAbsolutePath();
210 | // final OperatingSystem os = getCurrentPlatform();
211 | // if (os == OperatingSystem.OSX) {
212 | // try {
213 | // Runtime.getRuntime().exec(new String[] { "/usr/bin/open", absolutePath });
214 | // return;
215 | // } catch (IOException e) {
216 | // Logger.log("Couldn't open " + path + " through /usr/bin/open");
217 | // }
218 | // }
219 | // if (os == OperatingSystem.WINDOWS) {
220 | // final String cmd = String.format("cmd.exe /C start \"Open file\" \"%s\"", absolutePath);
221 | // try {
222 | // Runtime.getRuntime().exec(cmd);
223 | // return;
224 | // } catch (IOException e2) {
225 | // Logger.log("Couldn't open " + path + " through cmd.exe");
226 | // }
227 | // }
228 | // try {
229 | // final Class> desktopClass = Class.forName("java.awt.Desktop");
230 | // final Object desktop = desktopClass.getMethod("getDesktop", (Class[]) new Class[0]).invoke(null,
231 | // new Object[0]);
232 | // desktopClass.getMethod("browse", URI.class).invoke(desktop, path.toURI());
233 | // } catch (Throwable e3) {
234 | // Logger.log("Couldn't open " + path + " through Desktop.browse()");
235 | // }
236 | // }
237 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/Substitutor.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * @author Trxyy
7 | */
8 | public class Substitutor {
9 | /**
10 | * The map
11 | */
12 | private Map map;
13 |
14 | /**
15 | * The Constructor
16 | * @param map The map
17 | */
18 | public Substitutor(Map map) {
19 | this.map = map;
20 | }
21 |
22 | /**
23 | * Replace the String
24 | * @param str The String
25 | * @return The String remplaced
26 | */
27 | public String replace(String str) {
28 | StringBuilder sb = new StringBuilder();
29 | char[] strArray = str.toCharArray();
30 | int i = 0;
31 | while (i < strArray.length - 1) {
32 | if (strArray[i] == '$' && strArray[i + 1] == '{') {
33 | i = i + 2;
34 | int begin = i;
35 | while (strArray[i] != '}')
36 | ++i;
37 | sb.append(map.get(str.substring(begin, i++)));
38 | } else {
39 | sb.append(strArray[i]);
40 | ++i;
41 | }
42 | }
43 | if (i < strArray.length)
44 | sb.append(strArray[i]);
45 | return sb.toString();
46 | }
47 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/minecraft/utils/Version.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.minecraft.utils;
2 |
3 | public class Version {
4 |
5 | public String displayName;
6 | public String id;
7 | public String type;
8 | public String url;
9 |
10 | public Version() {
11 | }
12 |
13 | public Version(String dpName, String id_, String type_, String url_) {
14 | this.displayName = dpName;
15 | this.id = id_;
16 | this.type = type_;
17 | this.url = url_;
18 | }
19 |
20 | public String getDisplayName() {
21 | return displayName;
22 | }
23 |
24 | public String getId() {
25 | return id;
26 | }
27 |
28 | public String getType() {
29 | return type;
30 | }
31 |
32 | public String getUrl() {
33 | return url;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/settings/Encoder.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.settings;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | public class Encoder {
6 |
7 | private final static char[] ALPHABET = "tuvwxAlmnopqrsGHIJKRSTOPQ4567UVWXYZabcdBCDEFjkefghiyz0123LMN89+/".toCharArray();
8 |
9 | private static int[] toInt = new int[128];
10 |
11 | static {
12 | for (int i = 0; i < ALPHABET.length; i++) {
13 | toInt[ALPHABET[i]] = i;
14 | }
15 | }
16 |
17 | public static String encryptString(String txt) {
18 | String crypted = "";
19 | crypted = encrypt(txt);
20 | crypted = encrypt(crypted);
21 | return crypted;
22 | }
23 |
24 | public static String decryptString(String txt) {
25 | String uncrypted = "";
26 | uncrypted = decrypt(txt);
27 | uncrypted = decrypt(uncrypted);
28 | return uncrypted;
29 | }
30 |
31 | public static String encrypt(String text) {
32 | byte[] bytes = null;
33 | try {
34 | bytes = text.getBytes("UTF-8");
35 | } catch (UnsupportedEncodingException e) {
36 | }
37 | String encoded = Encoder.encode(bytes);
38 | return encoded;
39 | }
40 |
41 | public static String decrypt(String text) {
42 | byte[] decoded = Encoder.decode(text);
43 | return new String(decoded);
44 | }
45 |
46 | public static String encode(byte[] buf) {
47 | int size = buf.length;
48 | char[] ar = new char[((size + 2) / 3) * 4];
49 | int a = 0;
50 | int i = 0;
51 | while (i < size) {
52 | byte b0 = buf[i++];
53 | byte b1 = (i < size) ? buf[i++] : 0;
54 | byte b2 = (i < size) ? buf[i++] : 0;
55 |
56 | int mask = 0x3F;
57 | ar[a++] = ALPHABET[(b0 >> 2) & mask];
58 | ar[a++] = ALPHABET[((b0 << 4) | ((b1 & 0xFF) >> 4)) & mask];
59 | ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask];
60 | ar[a++] = ALPHABET[b2 & mask];
61 | }
62 | switch (size % 3) {
63 | case 1:
64 | ar[--a] = '=';
65 | case 2:
66 | ar[--a] = '=';
67 | }
68 | return new String(ar);
69 | }
70 |
71 | public static byte[] decode(String s) {
72 | int delta = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
73 | byte[] buffer = new byte[s.length() * 3 / 4 - delta];
74 | int mask = 0xFF;
75 | int index = 0;
76 | for (int i = 0; i < s.length(); i += 4) {
77 | int c0 = toInt[s.charAt(i)];
78 | int c1 = toInt[s.charAt(i + 1)];
79 | buffer[index++] = (byte) (((c0 << 2) | (c1 >> 4)) & mask);
80 | if (index >= buffer.length) {
81 | return buffer;
82 | }
83 | int c2 = toInt[s.charAt(i + 2)];
84 | buffer[index++] = (byte) (((c1 << 4) | (c2 >> 2)) & mask);
85 | if (index >= buffer.length) {
86 | return buffer;
87 | }
88 | int c3 = toInt[s.charAt(i + 3)];
89 | buffer[index++] = (byte) (((c2 << 6) | c3) & mask);
90 | }
91 | return buffer;
92 | }
93 |
94 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/settings/GameInfos.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.settings;
2 |
3 | public class GameInfos {
4 | public String resolution;
5 | public String vmArguments;
6 |
7 | public GameInfos() {}
8 |
9 | public GameInfos(String a, String e) {
10 | this.resolution = a;
11 | this.vmArguments = e;
12 | }
13 |
14 | public GameInfos(GameInfos o) {
15 | this.resolution = o.resolution;
16 | this.vmArguments = o.vmArguments;
17 | }
18 |
19 | public String getResolution() {
20 | return resolution;
21 | }
22 |
23 | public String getResolutionWidth() {
24 | String[] parts = this.resolution.split("x");
25 | return parts[0];
26 | }
27 |
28 | public String getResolutionHeight() {
29 | String[] parts = this.resolution.split("x");
30 | return parts[1];
31 | }
32 |
33 | public void setResolution(String reso) {
34 | this.resolution = reso;
35 | }
36 |
37 | public String getVmArguments() {
38 | return vmArguments;
39 | }
40 |
41 | public void setVmArguments(String receiveFriendsNotifications) {
42 | this.vmArguments = receiveFriendsNotifications;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/settings/GameSaver.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.settings;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileReader;
6 | import java.io.FileWriter;
7 | import java.io.IOException;
8 |
9 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
10 |
11 | public class GameSaver {
12 | public GameInfos infos;
13 | public File settingsFile;
14 | private GameEngine engine;
15 |
16 | public GameSaver(GameEngine engin) {
17 | this.engine = engin;
18 | String fileName = "game_settings";
19 | File folder = new File(this.engine.getGameFolder().getGameDir(), "private/settings");
20 | if (!folder.exists()) {
21 | folder.mkdirs();
22 | }
23 | this.settingsFile = new File(this.engine.getGameFolder().getGameDir(), "private/settings/" + fileName);
24 | if (!this.settingsFile.exists()) {
25 | try {
26 | settingsFile.createNewFile();
27 | writeConfig("854x480", "-Xmx1G -XX:-UseAdaptiveSizePolicy -Xmn128M");
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 | readConfig();
33 | }
34 |
35 | public GameSaver(GameInfos info, GameEngine engin) {
36 | this.infos = info;
37 | this.engine = engin;
38 | }
39 |
40 | public void saveSettings() {
41 | String fileName = "game_settings";
42 | File folder = new File(this.engine.getGameFolder().getGameDir(), "private/settings");
43 | if (!folder.exists()) {
44 | folder.mkdirs();
45 | }
46 | this.settingsFile = new File(this.engine.getGameFolder().getGameDir(), "private/settings/" + fileName);
47 | if (!this.settingsFile.exists()) {
48 | try {
49 | settingsFile.createNewFile();
50 | writeConfig("854x480", "-Xmx1G -XX:-UseAdaptiveSizePolicy -Xmn128M");
51 | } catch (IOException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 | else {
56 | writeConfig(infos.getResolution(), infos.getVmArguments());
57 | }
58 | }
59 |
60 | public void writeConfig(String... s) {
61 | try {
62 | FileWriter fw = new FileWriter(settingsFile);
63 | fw.write(Encoder.encryptString(s[0]) + ";");
64 | fw.write(Encoder.encryptString(s[1]));
65 | fw.close();
66 | } catch (IOException e) {
67 | System.out.println(e.toString());
68 | }
69 | }
70 |
71 | public GameInfos readConfig() {
72 | GameInfos accountRead = null;
73 | try {
74 | BufferedReader br = new BufferedReader(new FileReader(settingsFile));
75 | String line = br.readLine();
76 | String[] result = line.split(";");
77 | accountRead = new GameInfos(Encoder.decryptString(result[0]), Encoder.decryptString(result[1]));
78 | br.close();
79 | } catch (IOException e) {
80 | System.out.println(e.toString());
81 | }
82 | return accountRead;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/settings/UsernameSaver.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.settings;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileReader;
6 | import java.io.FileWriter;
7 | import java.io.IOException;
8 |
9 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
10 |
11 | public class UsernameSaver {
12 | public String username;
13 | public File settingsFile;
14 | private GameEngine engine;
15 |
16 | public UsernameSaver(GameEngine engin) {
17 | this.engine = engin;
18 | String fileName = "offline_user";
19 | File folder = new File(this.engine.getGameFolder().getGameDir(), "private/settings");
20 | if (!folder.exists()) {
21 | folder.mkdirs();
22 | }
23 | this.settingsFile = new File(this.engine.getGameFolder().getGameDir(), "private/settings/" + fileName);
24 | if (!this.settingsFile.exists()) {
25 | try {
26 | settingsFile.createNewFile();
27 | writeConfig("");
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 | String s = getUsername();
33 | System.out.println("username loaded: " + s);
34 | }
35 |
36 | public UsernameSaver(String names) {
37 | this.username = names;
38 | }
39 |
40 | public void saveSettings(String name) {
41 | String fileName = "offline_user";
42 | File folder = new File(this.engine.getGameFolder().getGameDir(), "private/settings");
43 | if (!folder.exists()) {
44 | folder.mkdirs();
45 | }
46 | this.settingsFile = new File(this.engine.getGameFolder().getGameDir(), "private/settings/" + fileName);
47 | if (!this.settingsFile.exists()) {
48 | try {
49 | settingsFile.createNewFile();
50 | writeConfig(name);
51 | } catch (IOException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 | else {
56 | writeConfig(name);
57 | }
58 | System.out.println("Wrote: " + name);
59 | }
60 |
61 | public void writeConfig(String s) {
62 | try {
63 | FileWriter fw = new FileWriter(settingsFile);
64 | fw.write(s);
65 | fw.close();
66 | } catch (IOException e) {
67 | System.out.println(e.toString());
68 | }
69 | }
70 |
71 | public String getUsername() {
72 | try {
73 | BufferedReader br = new BufferedReader(new FileReader(settingsFile));
74 | String line = br.readLine();
75 | br.close();
76 | return line;
77 | } catch (IOException e) {
78 | System.out.println(e.toString());
79 | }
80 | return "";
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/updater/Downloader.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.updater;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.File;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.net.URL;
8 | import java.net.URLConnection;
9 |
10 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
11 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.FileUtil;
12 |
13 | /**
14 | * @author Trxyy
15 | */
16 | public class Downloader extends Thread {
17 | /**
18 | * The download url
19 | */
20 | private final String url;
21 | /**
22 | * The Sha1
23 | */
24 | private final String sha1;
25 | /**
26 | * The file location
27 | */
28 | private final File file;
29 | /**
30 | * The gameEngine instance
31 | */
32 | private GameEngine engine;
33 |
34 | /**
35 | * Run the Thread
36 | */
37 | public void run() {
38 | try {
39 | download();
40 | } catch (IOException e) {
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | /**
46 | * The Constructor
47 | * @param file The file
48 | * @param url The Url
49 | * @param sha1 The Sha1
50 | * @param engine_ The gameEngine instance
51 | */
52 | public Downloader(File file, String url, String sha1, GameEngine engine_) {
53 | this.file = file;
54 | this.url = url;
55 | this.sha1 = sha1;
56 | this.engine = engine_;
57 | file.getParentFile().mkdirs();
58 | }
59 |
60 | /**
61 | * Download the file ion question
62 | * @throws IOException
63 | */
64 | public void download() throws IOException {
65 | System.out.println("Acquiring file '" + this.file.getName() + "'");
66 | engine.getGameUpdater().setCurrentFile(this.file.getName());
67 | if (this.file.getAbsolutePath().contains("assets")) {
68 | engine.getGameUpdater().setCurrentInfoText("Telechargement d'une ressource.");
69 | }
70 | else if (this.file.getAbsolutePath().contains("jre-legacy") || this.file.getAbsolutePath().contains("java-runtime-alpha")) {
71 | engine.getGameUpdater().setCurrentInfoText("Telechargement de java.");
72 | }
73 | else {
74 | engine.getGameUpdater().setCurrentInfoText("Telechargement d'une librairie.");
75 | }
76 | BufferedInputStream bufferedInputStream = null;
77 | FileOutputStream fileOutputStream = null;
78 | try {
79 | URL downloadUrl = new URL(this.url.replace(" ", "%20"));
80 | URLConnection urlConnection = downloadUrl.openConnection();
81 | urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36");
82 | bufferedInputStream = new BufferedInputStream(urlConnection.getInputStream());
83 | fileOutputStream = new FileOutputStream(this.file);
84 |
85 |
86 | byte[] data = new byte[1024];
87 | int read;
88 |
89 | while ((read = bufferedInputStream.read(data, 0, 1024)) != -1) {
90 | fileOutputStream.write(data, 0, read);
91 | }
92 | engine.getGameUpdater().downloadedFiles++;
93 | } finally {
94 | if (bufferedInputStream != null) {
95 | bufferedInputStream.close();
96 | }
97 | if (fileOutputStream != null) {
98 | fileOutputStream.close();
99 | }
100 | }
101 | // DEBUG SHA1
102 | // if (!FileUtil.matchSHA1(this.file, this.sha1)) {
103 | // System.out.println(this.file.getName() + " || " + FileUtil.getSHA(this.file));
104 | // }
105 | }
106 |
107 | /**
108 | * @return If the file require a update
109 | */
110 | public boolean requireUpdate() {
111 | if ((this.file.exists()) && (FileUtil.matchSHA1(this.file, this.sha1))) {
112 | return false;
113 | }
114 | return true;
115 | }
116 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/utils/FontLoader.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.utils;
2 |
3 | import java.awt.FontFormatException;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | import javafx.scene.text.Font;
8 | import javafx.scene.text.FontPosture;
9 |
10 | /**
11 | * @author Trxyy
12 | */
13 | public class FontLoader {
14 |
15 | /**
16 | * Load font from package
17 | * @param s The font name
18 | */
19 | public void loadFont(String s) {
20 | Font.loadFont(this.getClass().getResourceAsStream(String.valueOf("/resources/") + s), 14.0);
21 | }
22 |
23 | /**
24 | * Set the Font
25 | * @param fontName The font name
26 | * @param size The font size
27 | */
28 | public void setFont(String fontName, float size) {
29 | Font.font(fontName, (double) size);
30 | }
31 |
32 | /**
33 | * Load the font
34 | * @param fullFont The font name in package resources
35 | * @param fontName The font name
36 | * @param size The font size
37 | * @return A Font
38 | */
39 | public static Font loadFont(String fullFont, String fontName, float size) {
40 | Font.loadFont(FontLoader.class.getResourceAsStream(String.valueOf("/resources/") + fullFont), 14.0);
41 | final Font font = Font.font(fontName, (double) size);
42 | return font;
43 | }
44 |
45 | /**
46 | * Load the Font
47 | * @param fullFont The font name in package resources
48 | * @param fontName The font name
49 | * @param size The font size
50 | * @return A Font
51 | */
52 | public static Font loadFontItalic(String fullFont, String fontName, float size) {
53 | Font.loadFont(FontLoader.class.getResourceAsStream(String.valueOf("/resources/") + fullFont), 14.0);
54 | final Font font = Font.font(fontName, FontPosture.ITALIC, (double) size);
55 | return font;
56 | }
57 |
58 | /**
59 | * Load a font in AWT
60 | * @param fullFont The font name in package resources
61 | * @param fontName The font name
62 | * @param size The font size
63 | * @return A Font (AWT)
64 | */
65 | public static java.awt.Font loadFontAWT(String fullFont, String fontName, float size) {
66 | java.awt.Font font = null;
67 | InputStream is = FontLoader.class.getResourceAsStream(String.valueOf("/resources/" + fullFont));
68 | try {
69 | font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, is).deriveFont(java.awt.Font.PLAIN, 15f);
70 | } catch (FontFormatException e) {
71 | e.printStackTrace();
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | }
75 | font.deriveFont(size);
76 | return font;
77 | }
78 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_apiv2/utils/Mover.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_apiv2.utils;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public enum Mover {
7 | MOVE, DONT_MOVE;
8 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/AuthConfig.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | import java.io.File;
4 | import java.io.FileWriter;
5 | import java.io.IOException;
6 | import java.util.HashMap;
7 | import java.util.Map.Entry;
8 |
9 | import org.json.simple.JSONObject;
10 | import org.json.simple.JSONValue;
11 |
12 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
13 | import fr.trxyy.alternative.alternative_apiv2.minecraft.utils.JsonUtil;
14 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MicrosoftModel;
15 |
16 |
17 | public class AuthConfig {
18 |
19 | public File authConfig;
20 | public MicrosoftModel microsoftModel;
21 | public boolean read = false;
22 |
23 | /**
24 | * The Constructor
25 | * @param engine The GameEngine instance
26 | */
27 | public AuthConfig(GameEngine engine) {
28 | this.authConfig = new File(engine.getGameFolder().getGameDir(), "auth_infos.json");
29 | }
30 |
31 | public boolean canRefresh() {
32 | if (!this.authConfig.exists()) {
33 | return false;
34 | }
35 | else {
36 | return true;
37 | }
38 | }
39 |
40 | /**
41 | * Update a value in the config json
42 | */
43 | @SuppressWarnings("unchecked")
44 | public void createConfigFile(MicrosoftModel model) {
45 | if (!this.authConfig.exists()) {
46 | try {
47 | this.authConfig.createNewFile();
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | }
52 |
53 | JSONObject configDetails = new JSONObject();
54 | configDetails.put(EnumAuthConfig.ACCESS_TOKEN.getOption(), model.getAccess_token());
55 | configDetails.put(EnumAuthConfig.REFRESH_TOKEN.getOption(), model.getRefresh_token());
56 | configDetails.put(EnumAuthConfig.USER_ID.getOption(), model.getUser_id());
57 | configDetails.put(EnumAuthConfig.SCOPE.getOption(), model.getScope());
58 | configDetails.put(EnumAuthConfig.TOKEN_TYPE.getOption(), model.getToken_type());
59 | configDetails.put(EnumAuthConfig.EXPIRES_IN.getOption(), model.getExpires_in());
60 | configDetails.put(EnumAuthConfig.FOCI.getOption(), model.getFoci());
61 |
62 | try {
63 | FileWriter fw = new FileWriter(this.authConfig);
64 | JsonUtil.getGson().toJson(configDetails, fw);
65 | fw.flush();
66 | } catch (IOException e) {
67 | e.printStackTrace();
68 | }
69 | }
70 |
71 | /**
72 | * Get a specified value
73 | */
74 | public Object getValue(EnumAuthConfig option) {
75 | String configJson = JsonUtil.getGson().toJson(this.microsoftModel);
76 | JSONObject jsonObject = (JSONObject) JSONValue.parse(configJson);
77 | return jsonObject.get(option.getOption());
78 | }
79 |
80 | /**
81 | * Load the configuration
82 | */
83 | public void loadConfiguration() {
84 | String json = null;
85 | try {
86 | json = JsonUtil.loadJSON(this.authConfig.toURI().toURL().toString());
87 | this.read = true;
88 | } catch (IOException e) {
89 | Logger.err("ERROR !!!");
90 | e.printStackTrace();
91 | } finally {
92 | if (this.read) {
93 | this.microsoftModel = JsonUtil.getGson().fromJson(json, MicrosoftModel.class);
94 | }
95 | }
96 | }
97 |
98 |
99 | /**
100 | * Update a value in the config json
101 | */
102 | public void updateValue(String toUpdate, Object value) {
103 | this.loadConfiguration();
104 | String configJson = JsonUtil.getGson().toJson(this.microsoftModel);
105 | JSONObject jsonObject = (JSONObject) JSONValue.parse(configJson);
106 | jsonObject.put(toUpdate, value);
107 | try {
108 | FileWriter fileWriter = new FileWriter(this.authConfig);
109 | JsonUtil.getGson().toJson(jsonObject, fileWriter);
110 | fileWriter.flush();
111 | } catch (IOException e) {
112 | e.printStackTrace();
113 | }
114 | }
115 |
116 | /**
117 | * Update multiple values in the config json
118 | */
119 | public void updateValues(HashMap values) {
120 | this.loadConfiguration();
121 | String configJson = JsonUtil.getGson().toJson(this.microsoftModel);
122 | JSONObject jsonObject = (JSONObject) JSONValue.parse(configJson);
123 | for (Entry entry : values.entrySet()) {
124 | jsonObject.put(entry.getKey(), entry.getValue());
125 | }
126 |
127 | try {
128 | FileWriter fileWriter = new FileWriter(this.authConfig);
129 | JsonUtil.getGson().toJson(jsonObject, fileWriter);
130 | fileWriter.flush();
131 | } catch (IOException e) {
132 | e.printStackTrace();
133 | }
134 | }
135 |
136 | public void updateValues(MicrosoftModel model) {
137 | HashMap values = new HashMap();
138 | values.put(EnumAuthConfig.ACCESS_TOKEN.getOption(), model.getAccess_token());
139 | values.put(EnumAuthConfig.REFRESH_TOKEN.getOption(), model.getRefresh_token());
140 | values.put(EnumAuthConfig.USER_ID.getOption(), model.getUser_id());
141 | values.put(EnumAuthConfig.SCOPE.getOption(), model.getScope());
142 | values.put(EnumAuthConfig.TOKEN_TYPE.getOption(), model.getToken_type());
143 | values.put(EnumAuthConfig.EXPIRES_IN.getOption(), model.getExpires_in());
144 | values.put(EnumAuthConfig.FOCI.getOption(), model.getFoci());
145 | this.updateValues(values);
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/AuthConstants.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | import java.nio.charset.Charset;
4 |
5 | import com.google.gson.Gson;
6 | import com.google.gson.GsonBuilder;
7 |
8 | public class AuthConstants {
9 | /**
10 | * Mojang Auth Constants
11 | */
12 | public static String MOJANG_BASE_URL = "https://authserver.mojang.com/authenticate";
13 | /**
14 | * Microsoft Auth Constants
15 | */
16 | public static String MICROSOFT_BASE_URL = "https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&response_type=code&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf&scope=XboxLive.signin%20offline_access";
17 | public static String MICROSOFT_RESPONSE_URL = "https://login.live.com/oauth20_desktop.srf?code=";
18 | public static String MICROSOFT_AUTHENTICATE_XBOX = "https://user.auth.xboxlive.com/user/authenticate";
19 | public static String MICROSOFT_AUTHORIZE_XSTS = "https://xsts.auth.xboxlive.com/xsts/authorize";
20 | public static String MICROSOFT_LOGIN_XBOX = "https://api.minecraftservices.com/authentication/login_with_xbox";
21 | public static String MICROSOFT_MINECRAFT_STORE = "https://api.minecraftservices.com/entitlements/mcstore";
22 | public static String MICROSOFT_MINECRAFT_PROFILE = "https://api.minecraftservices.com/minecraft/profile";
23 | public static String MICROSOFT_AUTH_TOKEN = "https://login.live.com/oauth20_token.srf";
24 | /**
25 | * Utils Constants
26 | */
27 | public static String APP_JSON = "application/json";
28 | public static String URL_ENCODED = "application/x-www-form-urlencoded";
29 | public static Charset UTF_8 = Charset.forName("UTF-8");
30 |
31 | /**
32 | * Library Constants
33 | */
34 | public static String VERSION_ID = "1.0.2";
35 |
36 | /**
37 | * @return A Gson to read json
38 | */
39 | public static Gson getGson() {
40 | final GsonBuilder gsonBuilder = new GsonBuilder();
41 | gsonBuilder.enableComplexMapKeySerialization();
42 | gsonBuilder.setPrettyPrinting();
43 | return gsonBuilder.create();
44 | }
45 |
46 | /**
47 | * Display some copyrights
48 | */
49 | public static void displayCopyrights() {
50 | Logger.log("========================================");
51 | Logger.log("| AlternativeAuth |");
52 | Logger.log("| Version: " + getVersion() + " |");
53 | Logger.log("========================================");
54 | }
55 |
56 | private static String getVersion() {
57 | return VERSION_ID;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/Authenticator.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.CookieHandler;
5 | import java.net.CookieManager;
6 | import java.net.CookiePolicy;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import org.apache.commons.logging.Log;
11 |
12 | public class Authenticator {
13 |
14 | public void loginWithCredentials(String email, String password) {
15 | CookieHandler currentHandler = CookieHandler.getDefault();
16 | CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
17 |
18 | Map params = new HashMap();
19 | params.put("login", email);
20 | params.put("loginfmt", email);
21 | params.put("passwd", password);
22 |
23 |
24 |
25 | }
26 |
27 | public void test() {
28 | try {
29 | Map values = getUrlValues("https://login.live.com/oauth20_desktop.srf?code=M.R3_BL2.dadd3368-e0aa-123a-a51e-75549a49235e");
30 | String formId = values.get("code");
31 | Logger.log("code " + formId);
32 | } catch (UnsupportedEncodingException e) {
33 | Logger.err("Error " + e.getMessage());
34 | }
35 | }
36 |
37 | public Map getUrlValues(String url) throws UnsupportedEncodingException {
38 | int i = url.indexOf("?");
39 | Map paramsMap = new HashMap();
40 | if (i > -1) {
41 | String searchURL = url.substring(url.indexOf("?") + 1);
42 | String params[] = searchURL.split("&");
43 |
44 | for (String param : params) {
45 | String temp[] = param.split("=");
46 | paramsMap.put(temp[0], java.net.URLDecoder.decode(temp[1], "UTF-8"));
47 | }
48 | }
49 |
50 | return paramsMap;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/EnumAuthConfig.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | public enum EnumAuthConfig {
4 |
5 | ACCESS_TOKEN("access_token"),
6 | REFRESH_TOKEN("refresh_token"),
7 | USER_ID("user_id"),
8 | SCOPE("scope"),
9 | TOKEN_TYPE("token_type"),
10 | EXPIRES_IN("expires_in"),
11 | FOCI("foci");
12 |
13 | public String option;
14 | public Object def;
15 |
16 | EnumAuthConfig(String opt) {
17 | this.option = opt;
18 | }
19 |
20 | public String getOption() {
21 | return this.option;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/GameAuth.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | import fr.trxyy.alternative.alternative_apiv2.base.GameEngine;
4 | import fr.trxyy.alternative.alternative_authv2.microsoft.MicrosoftAuth;
5 | import fr.trxyy.alternative.alternative_authv2.microsoft.ParamType;
6 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MicrosoftModel;
7 | import javafx.collections.ListChangeListener;
8 | import javafx.scene.layout.Pane;
9 | import javafx.scene.web.WebEngine;
10 | import javafx.scene.web.WebHistory;
11 | import javafx.scene.web.WebView;
12 | import javafx.stage.Stage;
13 |
14 | /**
15 | * @author Trxyy
16 | */
17 | public class GameAuth {
18 | /**
19 | * Is player authed ?
20 | */
21 | public boolean isAuthenticated = false;
22 | /**
23 | * The session
24 | */
25 | private Session session = new Session();
26 |
27 | private AuthConfig authConfig;
28 |
29 | /**
30 | * Connect to minecraft with a Microsoft account
31 | *
32 | * @param root The parent to show in
33 | * @return The result in a WebView
34 | */
35 | public WebView connectMicrosoft(Pane root, GameEngine engine) {
36 | this.authConfig = new AuthConfig(engine);
37 | final WebView webView = new WebView();
38 | final WebEngine webEngine = webView.getEngine();
39 | webEngine.load(AuthConstants.MICROSOFT_BASE_URL);
40 | webEngine.setJavaScriptEnabled(true);
41 | webView.setPrefWidth(500);
42 | webView.setPrefHeight(600);
43 | root.getChildren().add(webView);
44 | webEngine.getHistory().getEntries().addListener((ListChangeListener) c -> {
45 | if (c.next() && c.wasAdded()) {
46 | c.getAddedSubList().forEach(entry -> {
47 | try {
48 | if (this.authConfig.canRefresh()) {
49 | Logger.log("Trying to logIn with RefreshToken.");
50 | this.authConfig.loadConfiguration();
51 | MicrosoftModel model = null;
52 | try {
53 | model = new MicrosoftAuth().getAuthorizationCode(ParamType.REFRESH, authConfig.microsoftModel.getRefresh_token());
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | }
57 | authConfig.updateValues(model);
58 | Session result = null;
59 | try {
60 | result = new MicrosoftAuth().getLiveToken(model.getAccess_token());
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | if (entry.getUrl().startsWith(AuthConstants.MICROSOFT_RESPONSE_URL)) {
64 | String authCode = entry.getUrl().substring(entry.getUrl().indexOf("=") + 1, entry.getUrl().indexOf("&"));
65 | MicrosoftModel model2 = new MicrosoftAuth().getAuthorizationCode(ParamType.AUTH, authCode);
66 | authConfig.createConfigFile(model2);
67 | Session result2 = new MicrosoftAuth().getLiveToken(model2.getAccess_token());
68 | this.setSession(result2.getUsername(), result2.getToken(), result2.getUuid());
69 | Stage stage = (Stage) root.getScene().getWindow();
70 | stage.close();
71 | } else {
72 | this.isAuthenticated = false;
73 | }
74 | }
75 | this.setSession(result.getUsername(), result.getToken(), result.getUuid());
76 | Stage stage = (Stage) root.getScene().getWindow();
77 | stage.close();
78 | }
79 | else {
80 | if (entry.getUrl().startsWith(AuthConstants.MICROSOFT_RESPONSE_URL)) {
81 | String authCode = entry.getUrl().substring(entry.getUrl().indexOf("=") + 1, entry.getUrl().indexOf("&"));
82 | MicrosoftModel model = new MicrosoftAuth().getAuthorizationCode(ParamType.AUTH, authCode);
83 | authConfig.createConfigFile(model);
84 | Session result = new MicrosoftAuth().getLiveToken(model.getAccess_token());
85 | this.setSession(result.getUsername(), result.getToken(), result.getUuid());
86 | Stage stage = (Stage) root.getScene().getWindow();
87 | stage.close();
88 | } else {
89 | this.isAuthenticated = false;
90 | }
91 | }
92 | } catch (Exception e) {
93 | e.printStackTrace();
94 | ;
95 | }
96 | });
97 | }
98 | });
99 | return webView;
100 | }
101 |
102 | /**
103 | * Set the session credentials
104 | * @param user
105 | * @param token
106 | * @param id
107 | */
108 | private void setSession(String user, String token, String id) {
109 | this.session.setUsername(user);
110 | this.session.setToken(token);
111 | this.session.setUuid(id);
112 | this.isAuthenticated = true;
113 | Logger.log("Connected Successfully !");
114 | }
115 |
116 | /**
117 | * @return If the user is successfully authenticated
118 | */
119 | public boolean isLogged() {
120 | return this.isAuthenticated;
121 | }
122 |
123 | /**
124 | * @return The session of the user
125 | */
126 | public Session getSession() {
127 | return this.session;
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/Logger.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class Logger {
7 |
8 | /**
9 | * Log a text
10 | * @param s The text to log
11 | */
12 | public static void log(String s) {
13 | System.out.println(getName() + s);
14 | }
15 |
16 | /**
17 | * Log a text with error
18 | * @param s The text to log
19 | */
20 | public static void err(String s) {
21 | System.err.println(getName() + s);
22 | }
23 |
24 | private static String getName() {
25 | return "[AAuth]";
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/Session.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | /**
4 | * @author Trxyy
5 | */
6 | public class Session {
7 |
8 | /**
9 | * The username
10 | */
11 | public String username;
12 | /**
13 | * The token
14 | */
15 | public String token;
16 | /**
17 | * The UUID
18 | */
19 | public String uuId;
20 |
21 | /**
22 | * The Constructor
23 | */
24 | public Session() {}
25 |
26 | /**
27 | * The Constructor
28 | * @param user The username
29 | * @param tken The token
30 | * @param uid The uuid
31 | */
32 | public Session(String user, String tken, String uid) {
33 | this.username = user;
34 | this.token = tken;
35 | this.uuId = uid;
36 | }
37 |
38 | /**
39 | * The Constructor
40 | * @param same The Session
41 | */
42 | public Session(Session same) {
43 | this.username = same.username;
44 | this.token = same.token;
45 | this.uuId = same.uuId;
46 | }
47 |
48 | /**
49 | * @return The username
50 | */
51 | public String getUsername() {
52 | return username;
53 | }
54 |
55 | /**
56 | * @return The token
57 | */
58 | public String getToken() {
59 | return token;
60 | }
61 |
62 | /**
63 | * @return The UUID
64 | */
65 | public String getUuid() {
66 | return uuId;
67 | }
68 | /**
69 | * Set the username
70 | * @param name The username
71 | */
72 | public void setUsername(String name) {
73 | this.username = name;
74 | }
75 |
76 | /**
77 | * Set the token
78 | * @param tkn The token
79 | */
80 | public void setToken(String tkn) {
81 | this.token = tkn;
82 | }
83 |
84 | /**
85 | * Set the UUID
86 | * @param id The UUID
87 | */
88 | public void setUuid(String id) {
89 | this.uuId = id;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/base/TokenGenerator.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.base;
2 |
3 | import java.security.SecureRandom;
4 |
5 | /**
6 | * @author Trxyy
7 | */
8 | public class TokenGenerator {
9 |
10 | /**
11 | * The SecureRandom
12 | */
13 | protected static SecureRandom random = new SecureRandom();
14 |
15 | /**
16 | * Generate a token
17 | * @param username The username
18 | * @return The username with a random
19 | */
20 | public synchronized static String generateToken(String username) {
21 | long longToken = Math.abs(random.nextLong());
22 | String random = Long.toString(longToken, 16);
23 | return (username + ":" + random);
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/microsoft/AuthConstants.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.microsoft;
2 |
3 | import java.nio.charset.Charset;
4 |
5 | import com.google.gson.Gson;
6 | import com.google.gson.GsonBuilder;
7 |
8 | public class AuthConstants {
9 | /**
10 | * Mojang Auth Constants
11 | */
12 | public static String MOJANG_BASE_URL = "https://authserver.mojang.com/authenticate";
13 | /**
14 | * Microsoft Auth Constants
15 | */
16 | public static String MICROSOFT_BASE_URL = "https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&response_type=code&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf&scope=XboxLive.signin%20offline_access";
17 | public static String MICROSOFT_RESPONSE_URL = "https://login.live.com/oauth20_desktop.srf?code=";
18 | public static String MICROSOFT_AUTHENTICATE_XBOX = "https://user.auth.xboxlive.com/user/authenticate";
19 | public static String MICROSOFT_AUTHORIZE_XSTS = "https://xsts.auth.xboxlive.com/xsts/authorize";
20 | public static String MICROSOFT_LOGIN_XBOX = "https://api.minecraftservices.com/authentication/login_with_xbox";
21 | public static String MICROSOFT_MINECRAFT_STORE = "https://api.minecraftservices.com/entitlements/mcstore";
22 | public static String MICROSOFT_MINECRAFT_PROFILE = "https://api.minecraftservices.com/minecraft/profile";
23 | public static String MICROSOFT_AUTH_TOKEN = "https://login.live.com/oauth20_token.srf";
24 | /**
25 | * Utils Constants
26 | */
27 | public static String APP_JSON = "application/json";
28 | public static String URL_ENCODED = "application/x-www-form-urlencoded";
29 | public static Charset UTF_8 = Charset.forName("UTF-8");
30 |
31 | /**
32 | * Library Constants
33 | */
34 | public static String VERSION_ID = "1.0.2";
35 |
36 | /**
37 | * @return A Gson to read json
38 | */
39 | public static Gson getGson() {
40 | final GsonBuilder gsonBuilder = new GsonBuilder();
41 | gsonBuilder.enableComplexMapKeySerialization();
42 | gsonBuilder.setPrettyPrinting();
43 | return gsonBuilder.create();
44 | }
45 |
46 | /**
47 | * Display some copyrights
48 | */
49 | public static void displayCopyrights() {
50 | System.out.println("========================================");
51 | System.out.println("| AlternativeAuth |");
52 | System.out.println("| Version: " + getVersion() + " |");
53 | System.out.println("========================================");
54 | }
55 |
56 | private static String getVersion() {
57 | return VERSION_ID;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/fr/trxyy/alternative/alternative_authv2/microsoft/MicrosoftAuth.java:
--------------------------------------------------------------------------------
1 | package fr.trxyy.alternative.alternative_authv2.microsoft;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.io.OutputStream;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 | import java.net.URLEncoder;
10 | import java.util.Collections;
11 | import java.util.HashMap;
12 | import java.util.Map;
13 | import java.util.Map.Entry;
14 | import java.util.stream.Collectors;
15 |
16 | import javax.net.ssl.HttpsURLConnection;
17 |
18 | import org.json.simple.JSONObject;
19 |
20 | import fr.trxyy.alternative.alternative_authv2.base.AuthConstants;
21 | import fr.trxyy.alternative.alternative_authv2.base.Logger;
22 | import fr.trxyy.alternative.alternative_authv2.base.Session;
23 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MicrosoftModel;
24 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MinecraftMicrosoftModel;
25 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MinecraftProfileModel;
26 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.MinecraftStoreModel;
27 | import fr.trxyy.alternative.alternative_authv2.microsoft.model.XboxLiveModel;
28 |
29 | public class MicrosoftAuth {
30 |
31 | public MicrosoftAuth() {
32 | Logger.log("Connecting to Microsoft services...");
33 | }
34 |
35 | public MicrosoftModel getAuthorizationCode(ParamType type, String authCode) throws Exception
36 | {
37 | MicrosoftModel model = AuthConstants.getGson().fromJson(this.connectMicrosoft(type, authCode), MicrosoftModel.class);
38 | Logger.log("Connecting with type: " + type);
39 | return model;
40 | }
41 |
42 | // public Session getAuthorizationCode(String authCode) throws Exception
43 | // {
44 | // MicrosoftModel model = AuthConstants.getGson().fromJson(this.connectMicrosoft(authCode), MicrosoftModel.class);
45 | //// model.getRefresh_token();
46 | // return this.getLiveToken(model.getAccess_token());
47 | // }
48 |
49 | public Session getLiveToken(String accessToken) throws Exception
50 | {
51 | XboxLiveModel model = AuthConstants.getGson().fromJson(this.postInformations(ParamType.XBL, AuthConstants.MICROSOFT_AUTHENTICATE_XBOX, accessToken, null), XboxLiveModel.class);
52 | return this.getXsts(model.getToken());
53 | }
54 |
55 | private Session getXsts(String liveToken) throws Exception
56 | {
57 | XboxLiveModel model = AuthConstants.getGson().fromJson(this.postInformations(ParamType.XSTS, AuthConstants.MICROSOFT_AUTHORIZE_XSTS, liveToken, null), XboxLiveModel.class);
58 | return this.getMinecraftToken(model.getDisplayClaims().getUsers()[0].getUhs(), model.getToken());
59 | }
60 |
61 | private Session getMinecraftToken(String userHash, String xstsToken) throws Exception
62 | {
63 | MinecraftMicrosoftModel model = AuthConstants.getGson().fromJson(this.postInformations(ParamType.MC, AuthConstants.MICROSOFT_LOGIN_XBOX, userHash, xstsToken), MinecraftMicrosoftModel.class);
64 | return this.checkMinecraftStore(model.getToken_type(), model.getAccess_token());
65 | }
66 |
67 | private Session checkMinecraftStore(String tokenType, String mcAccessToken)
68 | {
69 | MinecraftStoreModel model = AuthConstants.getGson().fromJson(this.connectToMinecraft(AuthConstants.MICROSOFT_MINECRAFT_STORE, tokenType + " " + mcAccessToken), MinecraftStoreModel.class);
70 | return this.getMinecraftProfile(tokenType, mcAccessToken);
71 | }
72 |
73 | private Session getMinecraftProfile(String tokenType, String mcAccessToken)
74 | {
75 | MinecraftProfileModel model = AuthConstants.getGson().fromJson(this.connectToMinecraft(AuthConstants.MICROSOFT_MINECRAFT_PROFILE, tokenType + " " + mcAccessToken), MinecraftProfileModel.class);
76 | final String uuidValid = model.getId().replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5");
77 | return new Session(model.getName(), mcAccessToken, uuidValid);
78 | }
79 |
80 | public String formatMicrosoft(ParamType paramType, String authCode) {
81 | final StringBuilder builder = new StringBuilder();
82 | try {
83 | for (Entry