refactored some parts of the PR

This commit is contained in:
FlorianMichael 2023-03-24 21:52:03 +01:00
parent 8ea2e6922f
commit 67e6be3788
7 changed files with 24 additions and 35 deletions

View File

@ -24,6 +24,7 @@ import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition;
import de.florianmichael.viafabricplus.definition.PackFormatsDefinition; import de.florianmichael.viafabricplus.definition.PackFormatsDefinition;
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler; import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen; import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.definition.c0_30.classicube.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.definition.c0_30.protocol.CustomClassicProtocolExtensions; import de.florianmichael.viafabricplus.definition.c0_30.protocol.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands; import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands;
import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition; import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition;
@ -52,6 +53,7 @@ public class ViaFabricPlus {
ClassicItemSelectionScreen.create(); ClassicItemSelectionScreen.create();
ChatLengthDefinition.create(); ChatLengthDefinition.create();
ClassicProtocolCommands.create(); ClassicProtocolCommands.create();
ClassiCubeAccountHandler.create();
new ProtocolHack(); new ProtocolHack();

View File

@ -43,8 +43,7 @@ public class ClassiCubeAccount {
public void login(ILoginProcessHandler processHandler) throws LoginException { public void login(ILoginProcessHandler processHandler) throws LoginException {
final ClassiCubeAuthenticationTokenRequest initialTokenRequest = new ClassiCubeAuthenticationTokenRequest(); final ClassiCubeAuthenticationTokenRequest initialTokenRequest = new ClassiCubeAuthenticationTokenRequest();
final ClassiCubeAuthenticationResponse initialTokenResponse = initialTokenRequest.send() final ClassiCubeAuthenticationResponse initialTokenResponse = initialTokenRequest.send().join();
.join();
// There should NEVER be any errors on the initial token response! // There should NEVER be any errors on the initial token response!
if (initialTokenResponse.shouldError()) { if (initialTokenResponse.shouldError()) {
@ -54,8 +53,7 @@ public class ClassiCubeAccount {
} }
final ClassiCubeAuthenticationLoginRequest loginRequest = new ClassiCubeAuthenticationLoginRequest(initialTokenResponse, this.username, this.password); final ClassiCubeAuthenticationLoginRequest loginRequest = new ClassiCubeAuthenticationLoginRequest(initialTokenResponse, this.username, this.password);
final ClassiCubeAuthenticationResponse loginResponse = loginRequest.send() final ClassiCubeAuthenticationResponse loginResponse = loginRequest.send().join();
.join();
if (loginResponse.shouldError()) { if (loginResponse.shouldError()) {
final String errorDisplay = loginResponse.getErrorDisplay(); final String errorDisplay = loginResponse.getErrorDisplay();

View File

@ -28,8 +28,7 @@ public class ClassiCubeAuthenticationData {
} }
public String getRequestBody() { public String getRequestBody() {
final StringBuilder builder = new StringBuilder("username=") final StringBuilder builder = new StringBuilder("username=").append(username);
.append(username);
builder.append("&password="); builder.append("&password=");
builder.append(password); builder.append(password);

View File

@ -3,6 +3,7 @@ package de.florianmichael.viafabricplus.definition.c0_30.classicube.auth.process
import de.florianmichael.viafabricplus.definition.c0_30.classicube.auth.ClassiCubeAccount; import de.florianmichael.viafabricplus.definition.c0_30.classicube.auth.ClassiCubeAccount;
public interface ILoginProcessHandler { public interface ILoginProcessHandler {
void handleMfa(final ClassiCubeAccount account); void handleMfa(final ClassiCubeAccount account);
void handleSuccessfulLogin(final ClassiCubeAccount account); void handleSuccessfulLogin(final ClassiCubeAccount account);
} }

View File

@ -2,33 +2,17 @@ package de.florianmichael.viafabricplus.definition.c0_30.classicube.data;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
public class ClassiCubeServerInfo { public record ClassiCubeServerInfo(
public final String hash; String hash,
public final int maxplayers; @SerializedName("maxplayers") int maxPlayers,
public final String name; String name,
public final int players; int players,
public final String software; String software,
public final long uptime; long uptime,
@SerializedName("country_abbr") @SerializedName("country_abbr") String countryCode,
public final String countryCode; boolean web,
public final boolean web; boolean featured,
public final boolean featured; String ip,
public final String ip; int port,
public final int port; String mppass) {
public final String mppass;
public ClassiCubeServerInfo(String hash, int maxplayers, String name, int players, String software, long uptime, String countryCode, boolean web, boolean featured, String ip, int port, String mppass) {
this.hash = hash;
this.maxplayers = maxplayers;
this.name = name;
this.players = players;
this.software = software;
this.uptime = uptime;
this.countryCode = countryCode;
this.web = web;
this.featured = featured;
this.ip = ip;
this.port = port;
this.mppass = mppass;
}
} }

View File

@ -10,6 +10,7 @@ import java.net.http.HttpRequest;
public abstract class ClassiCubeRequest { public abstract class ClassiCubeRequest {
private final static URI CLASSICUBE_ROOT_URI = URI.create("https://www.classicube.net"); private final static URI CLASSICUBE_ROOT_URI = URI.create("https://www.classicube.net");
protected final static URI AUTHENTICATION_URI = CLASSICUBE_ROOT_URI.resolve("/api/login/"); protected final static URI AUTHENTICATION_URI = CLASSICUBE_ROOT_URI.resolve("/api/login/");
protected final static URI SERVER_INFO_URI = CLASSICUBE_ROOT_URI.resolve("/api/server/"); protected final static URI SERVER_INFO_URI = CLASSICUBE_ROOT_URI.resolve("/api/server/");
protected final static URI SERVER_LIST_INFO_URI = CLASSICUBE_ROOT_URI.resolve("/api/servers/"); protected final static URI SERVER_LIST_INFO_URI = CLASSICUBE_ROOT_URI.resolve("/api/servers/");

View File

@ -12,6 +12,10 @@ public class ClassiCubeServerInfoResponse extends ClassiCubeResponse {
this.servers = servers; this.servers = servers;
} }
public Set<ClassiCubeServerInfo> getServers() {
return servers;
}
public static ClassiCubeServerInfoResponse fromJson(final String json) { public static ClassiCubeServerInfoResponse fromJson(final String json) {
return GSON.fromJson(json, ClassiCubeServerInfoResponse.class); return GSON.fromJson(json, ClassiCubeServerInfoResponse.class);
} }