rename the package
This commit is contained in:
@ -0,0 +1,69 @@
|
||||
package cc.fascinated.model.token;
|
||||
|
||||
import cc.fascinated.model.server.JavaMinecraftServer;
|
||||
import cc.fascinated.model.server.MinecraftServer;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author Braydon
|
||||
*/
|
||||
@AllArgsConstructor @Getter @ToString
|
||||
public final class JavaServerStatusToken {
|
||||
|
||||
/**
|
||||
* The version of the server.
|
||||
*/
|
||||
private final JavaMinecraftServer.Version version;
|
||||
|
||||
/**
|
||||
* The players on the server.
|
||||
*/
|
||||
private final MinecraftServer.Players players;
|
||||
|
||||
/**
|
||||
* The mods running on this server.
|
||||
*/
|
||||
@SerializedName("modinfo")
|
||||
private JavaMinecraftServer.ForgeModInfo modInfo;
|
||||
|
||||
/**
|
||||
* The mods running on this server.
|
||||
* <p>
|
||||
* This is only used for servers
|
||||
* running 1.13 and above.
|
||||
* </p>
|
||||
*/
|
||||
private JavaMinecraftServer.ForgeData forgeData;
|
||||
|
||||
/**
|
||||
* The motd of the server.
|
||||
*/
|
||||
private final Object description;
|
||||
|
||||
/**
|
||||
* The favicon of the server.
|
||||
*/
|
||||
private final String favicon;
|
||||
|
||||
/**
|
||||
* Whether the server prevents chat reports.
|
||||
*/
|
||||
private boolean preventsChatReports;
|
||||
|
||||
/**
|
||||
* Whether the server enforces secure chat.
|
||||
*/
|
||||
private boolean enforcesSecureChat;
|
||||
|
||||
/**
|
||||
* Whether the server has previews chat enabled.
|
||||
* <p>
|
||||
* Chat Preview sends chat messages to the server as they are typed, even before they're sent.
|
||||
* <a href="https://www.minecraft.net/es-mx/article/minecraft-snapshot-22w19a">More information</a>
|
||||
* </p>
|
||||
*/
|
||||
private boolean previewsChat;
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package cc.fascinated.model.token;
|
||||
|
||||
import xyz.mcutils.backend.Main;
|
||||
import cc.fascinated.common.Tuple;
|
||||
import cc.fascinated.common.UUIDUtils;
|
||||
import cc.fascinated.model.player.Cape;
|
||||
import cc.fascinated.model.skin.Skin;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
@Getter @NoArgsConstructor @AllArgsConstructor
|
||||
public class MojangProfileToken {
|
||||
|
||||
/**
|
||||
* The UUID of the player.
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* The name of the player.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The properties of the player.
|
||||
*/
|
||||
private ProfileProperty[] properties = new ProfileProperty[0];
|
||||
|
||||
/**
|
||||
* Get the skin and cape of the player.
|
||||
*
|
||||
* @return the skin and cape of the player
|
||||
*/
|
||||
public Tuple<Skin, Cape> getSkinAndCape() {
|
||||
ProfileProperty textureProperty = getProfileProperty("textures");
|
||||
if (textureProperty == null) {
|
||||
return null;
|
||||
}
|
||||
JsonObject texturesJson = textureProperty.getDecodedValue().getAsJsonObject("textures"); // Parse the decoded JSON and get the texture object
|
||||
return new Tuple<>(Skin.fromJson(texturesJson.getAsJsonObject("SKIN")).populatePartUrls(this.getFormattedUuid()),
|
||||
Cape.fromJson(texturesJson.getAsJsonObject("CAPE")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatted UUID of the player.
|
||||
*
|
||||
* @return the formatted UUID
|
||||
*/
|
||||
public String getFormattedUuid() {
|
||||
return id.length() == 32 ? UUIDUtils.addDashes(id).toString() : id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a profile property for the player
|
||||
*
|
||||
* @return the profile property
|
||||
*/
|
||||
public ProfileProperty getProfileProperty(String name) {
|
||||
for (ProfileProperty property : properties) {
|
||||
if (property.getName().equals(name)) {
|
||||
return property;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Getter @NoArgsConstructor
|
||||
public static class ProfileProperty {
|
||||
/**
|
||||
* The name of the property.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The base64 value of the property.
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* The signature of the property.
|
||||
*/
|
||||
private String signature;
|
||||
|
||||
/**
|
||||
* Decodes the value for this property.
|
||||
*
|
||||
* @return the decoded value
|
||||
*/
|
||||
@JsonIgnore
|
||||
public JsonObject getDecodedValue() {
|
||||
return Main.GSON.fromJson(new String(Base64.getDecoder().decode(this.value)), JsonObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the property is signed.
|
||||
*
|
||||
* @return true if the property is signed, false otherwise
|
||||
*/
|
||||
public boolean isSigned() {
|
||||
return signature != null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cc.fascinated.model.token;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter @NoArgsConstructor
|
||||
public class MojangUsernameToUuidToken {
|
||||
|
||||
/**
|
||||
* The UUID of the player.
|
||||
*/
|
||||
@JsonProperty("id")
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
* The name of the player.
|
||||
*/
|
||||
@JsonProperty("name")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* Check if the profile is valid.
|
||||
*
|
||||
* @return if the profile is valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return uuid != null && username != null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user