Skip to content

Commit

Permalink
Updated a bunch to support mockbukkit 1.20.4 for Slimefun (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Walsh <[email protected]>
  • Loading branch information
J3fftw1 and WalshyDev authored Jan 13, 2024
1 parent c4231a4 commit a2364de
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dough-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.25</version>
<version>6.0.52</version>
<scope>provided</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion dough-skins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.25</version>
<version>6.0.52</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.mojang.authlib.properties.PropertyMap;
import org.bukkit.Bukkit;
import org.bukkit.inventory.meta.SkullMeta;

Expand Down Expand Up @@ -45,22 +46,24 @@ public final class CustomGameProfile extends GameProfile {
}

void apply(@Nonnull SkullMeta meta) throws NoSuchFieldException, IllegalAccessException, UnknownServerVersionException {
ReflectionUtils.setFieldValue(meta, "profile", this);

// Forces SkullMeta to properly deserialize and serialize the profile
// setOwnerProfile was added in 1.18, but setOwningPlayer throws a NullPointerException since 1.20.2
if (MinecraftVersion.get().isAtLeast(MinecraftVersion.parse("1.20"))) {
PlayerProfile playerProfile = Bukkit.createPlayerProfile(meta.getOwningPlayer().getUniqueId(), PLAYER_NAME);
PlayerProfile playerProfile = Bukkit.createPlayerProfile(UUID.randomUUID(), PLAYER_NAME);
PlayerTextures playerTextures = playerProfile.getTextures();
playerTextures.setSkin(this.skinUrl);
playerProfile.setTextures(playerTextures);
meta.setOwnerProfile(playerProfile);
} else {
ReflectionUtils.setFieldValue(meta, "profile", this);

meta.setOwningPlayer(meta.getOwningPlayer());

// Now override the texture again
ReflectionUtils.setFieldValue(meta, "profile", this);
}

// Now override the texture again
ReflectionUtils.setFieldValue(meta, "profile", this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import io.github.bakedlibs.dough.common.DoughLogger;

public final class PlayerSkin {
public class PlayerSkin {

private static final String ERROR_TOKEN = "error";

Expand Down

0 comments on commit a2364de

Please sign in to comment.