Skip to content

Commit

Permalink
Import from dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo0001 committed May 6, 2023
1 parent 079e279 commit 82172d5
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.jo0001</groupId>
<artifactId>ViaTesting</artifactId>
<version>1.0</version>
<version>1.1</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
56 changes: 55 additions & 1 deletion src/main/java/de/jo0001/viaTesting/core/Controller.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.jo0001.viaTesting.core;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import de.jo0001.viaTesting.util.UpdateCheck;
import javafx.application.Platform;
import javafx.collections.FXCollections;
Expand All @@ -22,11 +24,13 @@ public class Controller implements Initializable {
@FXML
CheckBox vB, vR, vRSup, aNether, aEnd;
@FXML
Button btn;
Button btn, loadBtn;
@FXML
Label inWorkNumber;
@FXML
ProgressBar inWorkProgress;
@FXML
TextField dumpUrl;
final int MAX_CONCURRENT_SETUPS = 4;

private int count = 0;
Expand Down Expand Up @@ -93,6 +97,15 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
Util.alert("Error", e.toString(), Alert.AlertType.ERROR);
}
});

loadBtn.setOnAction(actionEvent -> {
try {
loadFromDump();
} catch (Exception e) {
e.printStackTrace();
Util.alert("Error", e.toString(), Alert.AlertType.ERROR);
}
});
}

public void incrementCount() {
Expand Down Expand Up @@ -155,4 +168,45 @@ private void create() throws IOException {
Util.alert(MAX_CONCURRENT_SETUPS + " is a nice number", "Please wait. There are already " + MAX_CONCURRENT_SETUPS + " testing setups in work", Alert.AlertType.INFORMATION);
}
}

private void loadFromDump() throws IOException {
String dUrl = dumpUrl.getText();
if (dUrl.startsWith("https://dump.viaversion.com/")) {
dUrl = "https://dump.viaversion.com/raw/" + dUrl.split("/")[3];
JsonObject dumpData = DownloadUtil.getDumpData(dUrl);
JsonObject versionInfo = dumpData.getAsJsonObject("versionInfo");
boolean isProxy = false;
String platform = versionInfo.get("platformName").getAsString();
if (platform.equalsIgnoreCase("Waterfall")) {
proxyCB.setValue("Waterfall with Via");
isProxy = true;
} else if (platform.equalsIgnoreCase("BungeeCord")) {
proxyCB.setValue("Bungee with Via");
isProxy = true;
}

for (JsonElement element : versionInfo.getAsJsonArray("subPlatforms")) {
String sub = element.getAsString();
if (sub.contains("ViaBackwards")) {
vB.setSelected(true);
} else if (sub.contains("ViaRewind")) {
vR.setSelected(true);
}
}

if (!isProxy) {//don't set version or check for VRLS on proxies
String version = Util.idToVersion(versionInfo.get("serverProtocol").getAsInt());
if (!version.equalsIgnoreCase("Unknown")) {
versionCB.setValue(version);
}

for (JsonElement el : dumpData.getAsJsonObject("platformDump").getAsJsonArray("plugins")) {
if (el.getAsJsonObject().get("name").getAsString().equalsIgnoreCase("ViaRewind-Legacy-Support")) {
vRSup.setSelected(true);
break;
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/jo0001/viaTesting/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void start(Stage primaryStage) throws Exception {
Parent root = loader.load();
Controller controller = loader.getController();
primaryStage.setTitle("ViaTesting - " + VERSION);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.setScene(new Scene(root, 600, 430));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/logo-256.png")));
primaryStage.resizableProperty().setValue(Boolean.FALSE);
primaryStage.getScene().getStylesheets().add(Main.class.getResource("/style.css").toExternalForm());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/de/jo0001/viaTesting/util/DownloadUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static JsonObject getLatestViaTesting() throws IOException {
return fetchData("https://api.github.com/repos/Jo0001/ViaTesting/releases/latest");
}

public static JsonObject getDumpData(String url) throws IOException {
return fetchData(url);
}

private static JsonObject fetchData(String url) throws IOException {
//stolen from Eduard
final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
Expand Down
74 changes: 72 additions & 2 deletions src/main/java/de/jo0001/viaTesting/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public static void alert(String title, String message, Alert.AlertType alertType
});
}

public static void alert(String ex){
public static void alert(String ex) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle( "ViaTesting - Error");
alert.setTitle("ViaTesting - Error");
alert.setHeaderText(null);
alert.setContentText(ex);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
Expand All @@ -35,4 +35,74 @@ public static void alert(String ex){
Platform.exit();
});
}

public static String idToVersion(final int id) {
switch (id) {
case 47:
return "1.8.8";
case 110:
return "1.9.4";
case 210:
return "1.10.2";
case 316:
return "1.11.2";
case 335:
return "1.12";
case 338:
return "1.12.1";
case 340:
return "1.12.2";
case 393:
return "1.13";
case 401:
return "1.13.1";
case 404:
return "1.13.2";
case 477:
return "1.14";
case 480:
return "1.14.1";
case 485:
return "1.14.2";
case 490:
return "1.14.3";
case 498:
return "1.14.4";
case 573:
return "1.15";
case 575:
return "1.15.1";
case 578:
return "1.15.2";
case 735:
return "1.16";
case 736:
return "1.16.1";
case 751:
return "1.16.2";
case 753:
return "1.16.3";
case 754:
return "1.16.5";
case 755:
return "1.17";
case 756:
return "1.17.1";
case 757:
return "1.18.1";
case 758:
return "1.18.2";
case 759:
return "1.19";
case 760:
return "1.19.2";
case 761:
return "1.19.3";
case 762:
return "1.19.4";
default:
return "Unknown";
}

}
}
30 changes: 20 additions & 10 deletions src/main/resources/core.fxml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.collections.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="430.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="de.jo0001.viaTesting.core.Controller">
<center>
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
Expand Down Expand Up @@ -49,10 +55,14 @@
<Label layoutX="20.0" layoutY="234.0" prefHeight="17.0" prefWidth="40.0" text="Misc"/>
<CheckBox fx:id="aNether" layoutX="165.0" layoutY="234.0" mnemonicParsing="false" text="Allow Nether"/>
<CheckBox fx:id="aEnd" layoutX="275.0" layoutY="234.0" mnemonicParsing="false" text="Allow End"/>
<Label layoutX="18.0" layoutY="304.0" text="Testing Setups in work"/>
<Label fx:id="inWorkNumber" layoutX="142.0" layoutY="304.0"/>
<ProgressBar fx:id="inWorkProgress" layoutX="165.0" layoutY="304.0" prefWidth="165.0" progress="0.0"/>
<Button fx:id="btn" layoutX="165.0" layoutY="349.0" mnemonicParsing="false" text="Create"/>
<Label layoutX="18.0" layoutY="279.0" text="Import from dump"/>
<TextField fx:id="dumpUrl" layoutX="165.0" layoutY="279.0" prefHeight="25.0" prefWidth="280.0"
promptText="https://dump.viaversion.com/0123456789abcdef"/>
<Label layoutX="18.0" layoutY="332.0" text="Testing Setups in work"/>
<Label fx:id="inWorkNumber" layoutX="142.0" layoutY="332.0"/>
<ProgressBar fx:id="inWorkProgress" layoutX="165.0" layoutY="332.0" prefWidth="165.0" progress="0.0"/>
<Button fx:id="btn" layoutX="165.0" layoutY="377.0" mnemonicParsing="false" text="Create"/>
<Button fx:id="loadBtn" layoutX="455.0" layoutY="279.0" mnemonicParsing="false" text="Load"/>
</AnchorPane>
</center>
</BorderPane>

0 comments on commit 82172d5

Please sign in to comment.