Skip to content

Commit

Permalink
feat: Removed SkinOptions and the unused CompletableFutureManager class
Browse files Browse the repository at this point in the history
BREAKING CHAANGE: SkinOptions have been removed and Skin now uses the new SkinPart
  • Loading branch information
GeorgeV220 committed Oct 12, 2023
1 parent 73cb9c3 commit 511866e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.georgev22.skinoverlay.SkinOverlay;
import com.georgev22.skinoverlay.event.events.player.PlayerObjectConnectionEvent;
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.utilities.SkinOptions;
import com.georgev22.skinoverlay.handler.skin.SkinParts;
import com.georgev22.skinoverlay.utilities.SerializableBufferedImage;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
Expand Down Expand Up @@ -72,10 +73,10 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
skinOverlay.getSkinHandler().setSkin(playerObject, skin);
} else {
if (subChannel.equalsIgnoreCase("change")) {
if (!skin.skinOptions().getSkinName().contains("custom")) {
if (!skin.skinParts().getSkinName().contains("custom")) {
skinOverlay.getSkinHandler().setSkin(playerObject, skin);
} else {
URL url = new URL(skin.skinOptions().getUrl());
URL url = new URL(Objects.requireNonNull(skin.skinURL()));
ByteArrayOutputStream output = new ByteArrayOutputStream();

try (InputStream stream = url.openStream()) {
Expand All @@ -89,10 +90,11 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
output.write(buffer, 0, bytesRead);
}
}
skin.setSkinParts(new SkinParts(new SerializableBufferedImage(ImageIO.read(new ByteArrayInputStream(output.toByteArray()))), skin.skinParts().getSkinName()));
skinOverlay.getSkinHandler().retrieveOrGenerateSkin(
playerObject,
() -> ImageIO.read(new ByteArrayInputStream(output.toByteArray())),
new SkinOptions()).thenAccept(userSkin -> {
() -> skin.skinParts().getFullSkin().getBufferedImage(),
skin.skinParts()).thenAccept(userSkin -> {
skinOverlay.getSkinHandler().setSkin(playerObject, skin);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private void setupDatabase() throws Exception {
ObjectMap<String, Pair<String, String>> skinMap = new HashObjectMap<String, Pair<String, String>>()
.append("entity_id", Pair.create("VARCHAR(38)", "NULL"))
.append("property", Pair.create("BLOB", "NULL"))
.append("skinOptions", Pair.create("BLOB", "NULL"));
.append("skinParts", Pair.create("BLOB", "NULL"));
switch (OptionsUtil.DATABASE_TYPE.getStringValue()) {
case "MySQL" -> {
if (databaseWrapper == null || !databaseWrapper.isConnected()) {
Expand Down
41 changes: 23 additions & 18 deletions core/src/main/java/com/georgev22/skinoverlay/handler/Skin.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.georgev22.skinoverlay.handler;

import com.georgev22.library.utilities.EntityManager.Entity;
import com.georgev22.skinoverlay.utilities.SkinOptions;
import com.georgev22.skinoverlay.SkinOverlay;
import com.georgev22.skinoverlay.handler.skin.SkinParts;
import com.georgev22.skinoverlay.utilities.SerializableBufferedImage;
import com.google.gson.JsonParser;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.util.Base64;
import java.util.UUID;
import java.util.logging.Level;

@ApiStatus.NonExtendable
public class Skin extends Entity implements Serializable {
Expand All @@ -18,45 +22,46 @@ public class Skin extends Entity implements Serializable {
private static final long serialVersionUID = 2L;

private SProperty property;
private SkinOptions skinOptions;
private SkinParts skinParts;

public Skin(UUID uuid) {
super(uuid);
addCustomData("entity_id", uuid.toString());
this.skinOptions = new SkinOptions();
}

public Skin(UUID uuid, SProperty sProperty) {
super(uuid);
addCustomData("entity_id", uuid.toString());
addCustomData("property", this.property = sProperty);
addCustomData("skinOptions", this.skinOptions = new SkinOptions());
this.skinParts = new SkinParts();
}

public Skin(UUID uuid, SProperty sProperty, String skinName) {
super(uuid);
addCustomData("entity_id", uuid.toString());
addCustomData("property", this.property = sProperty);
addCustomData("skinOptions", this.skinOptions = new SkinOptions(skinName));
try {
addCustomData("skinParts", this.skinParts = new SkinParts(
new SerializableBufferedImage(SkinOverlay.getInstance().getSkinHandler().getSkinImage(sProperty)),
skinName
));
} catch (IOException e) {
SkinOverlay.getInstance().getLogger().log(Level.SEVERE, "Could not load skin " + skinName, e);
addCustomData("skinParts", this.skinParts = new SkinParts(null, skinName));
}
}

public Skin(UUID uuid, SProperty sProperty, SkinOptions skinOptions) {
public Skin(UUID uuid, SProperty sProperty, SkinParts skinParts) {
super(uuid);
addCustomData("entity_id", uuid.toString());
addCustomData("property", this.property = sProperty);
addCustomData("skinOptions", this.skinOptions = skinOptions);
addCustomData("skinParts", this.skinParts = skinParts);
}

public @Nullable SProperty skinProperty() {
return getCustomData("property") != null ? getCustomData("property") : property;
}

public SkinOptions skinOptions() {
return getCustomData("skinOptions") != null ? getCustomData("skinOptions") : skinOptions;
public SkinParts skinParts() {
return getCustomData("skinParts") != null ? getCustomData("skinParts") : skinParts;
}

public void setSkinOptions(SkinOptions skinOptions) {
addCustomData("skinOptions", this.skinOptions = skinOptions);
public void setSkinParts(SkinParts skinParts) {
addCustomData("skinParts", this.skinParts = skinParts);
}

public void setProperty(SProperty property) {
Expand All @@ -76,7 +81,7 @@ public void setProperty(SProperty property) {
public String toString() {
return "Skin{" +
"property=" + property +
", skinOptions=" + skinOptions +
", skinParts=" + skinParts +
", skinURL=" + skinURL() +
'}';
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 511866e

Please sign in to comment.