Skip to content

Commit fa18d20

Browse files
committed
merge to CraftedCore 5.3
1 parent 1889d87 commit fa18d20

File tree

9 files changed

+25
-90
lines changed

9 files changed

+25
-90
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
SkinShifter 1..1
1+
SkinShifter 1.1
22
================
33

44
- run different tasks asynchronous to fix stuck when running commands with bad internet connection
55
- change player chat name
66
- performance improvements
7+
- merge caching to CraftedCore
78

89
SkinShifter 1.0
910
================

common/src/main/java/dev/tocraft/skinshifter/SkinShifter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import dev.tocraft.skinshifter.data.SkinPlayerData;
44
import net.minecraft.nbt.Tag;
5-
import net.minecraft.resources.ResourceLocation;
65
import net.minecraft.server.level.ServerPlayer;
76
import net.minecraft.world.entity.player.Player;
87
import tocraft.craftedcore.config.ConfigLoader;
98
import tocraft.craftedcore.event.common.CommandEvents;
10-
import tocraft.craftedcore.patched.Identifier;
119
import tocraft.craftedcore.patched.TComponent;
1210
import tocraft.craftedcore.platform.VersionChecker;
1311
import tocraft.craftedcore.registration.PlayerDataRegistry;
@@ -30,6 +28,10 @@ public void initialize() {
3028
CommandEvents.REGISTRATION.register(new SkinShifterCommand());
3129
}
3230

31+
/**
32+
* @param player the player the skin should be set of
33+
* @param skinPlayer the uuid of the owner of the new skin
34+
*/
3335
public static void setSkin(ServerPlayer player, UUID skinPlayer) {
3436
if (Objects.equals(player.getUUID(), skinPlayer)) {
3537
SkinPlayerData.setSkin(player, null);
@@ -38,6 +40,10 @@ public static void setSkin(ServerPlayer player, UUID skinPlayer) {
3840
}
3941
}
4042

43+
/**
44+
* @param player the player that is being tested
45+
* @return the uuid of the owner of the current skin the player wears
46+
*/
4147
public static UUID getCurrentSkin(Player player) {
4248
Tag currentSkinTag = PlayerDataRegistry.readTag(player, TAG_NAME);
4349
if (currentSkinTag != null) {
@@ -50,8 +56,4 @@ public static UUID getCurrentSkin(Player player) {
5056
// fallback
5157
return player.getUUID();
5258
}
53-
54-
public static ResourceLocation id(String name) {
55-
return Identifier.parse(MODID, name);
56-
}
5759
}

common/src/main/java/dev/tocraft/skinshifter/SkinShifterCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void onRegister(CommandDispatcher<CommandSourceStack> dispatcher) {
7575
LiteralCommandNode<CommandSourceStack> changeChatName = Commands.literal("changeChatName")
7676
.executes(context -> {
7777
boolean bool = SkinShifter.CONFIG.changeChatName;
78-
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.config.get", "changeChatName", String.valueOf(bool)), true);
78+
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("craftedcore.config.get", "changeChatName", String.valueOf(bool)), true);
7979
return 1;
8080
})
8181
.then(Commands.argument("value", BoolArgumentType.bool())
@@ -84,7 +84,7 @@ private void onRegister(CommandDispatcher<CommandSourceStack> dispatcher) {
8484
SkinShifter.CONFIG.changeChatName = bool;
8585
SkinShifter.CONFIG.save();
8686
SkinShifter.CONFIG.sendToAllPlayers(context.getSource().getLevel());
87-
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.config.set", "changeChatName", String.valueOf(bool)), true);
87+
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("craftedcore.config.set", "changeChatName", String.valueOf(bool)), true);
8888
return 1;
8989
})).build();
9090

common/src/main/java/dev/tocraft/skinshifter/data/SkinCache.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

common/src/main/java/dev/tocraft/skinshifter/data/SkinPlayerData.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
import tocraft.craftedcore.platform.PlayerProfile;
1010
import tocraft.craftedcore.registration.PlayerDataRegistry;
1111

12-
import java.util.Map;
1312
import java.util.UUID;
1413
import java.util.concurrent.CompletableFuture;
15-
import java.util.concurrent.ConcurrentHashMap;
1614

1715
@ApiStatus.Internal
1816
public class SkinPlayerData {
1917
public static final String TAG_NAME = "CurrentSkin";
20-
private static final Map<UUID, PlayerProfile> CACHED_SKINS = new ConcurrentHashMap<>();
2118

2219
public static void initialize() {
2320
PlayerDataRegistry.registerKey(TAG_NAME, true, true);
@@ -27,17 +24,13 @@ public static void initialize() {
2724
public static PlayerProfile getSkin(Player player) {
2825
UUID uuid = SkinShifter.getCurrentSkin(player);
2926
if (uuid != player.getUUID()) {
30-
// TODO: Replace with CraftedCore's Caching methods to save RAM
31-
if (!CACHED_SKINS.containsKey(uuid)) {
32-
// do this in an external thread so the game isn't stuck with bad internet connection (might take some time for skin to load, though)
33-
CompletableFuture.runAsync(() -> {
34-
PlayerProfile skin = PlayerProfile.ofId(uuid);
35-
CACHED_SKINS.put(uuid, skin);
36-
});
37-
}
38-
39-
return CACHED_SKINS.get(uuid);
27+
PlayerProfile playerProfile = PlayerProfile.getCachedProfile(uuid);
28+
if (playerProfile == null) {
29+
// cache profile asynchronous
30+
CompletableFuture.runAsync(() -> PlayerProfile.ofId(uuid));
4031
}
32+
return playerProfile;
33+
}
4134

4235
return null;
4336
}

common/src/main/java/dev/tocraft/skinshifter/mixin/client/AbstractClientPlayerMixin.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.tocraft.skinshifter.mixin.client;
22

33
import dev.tocraft.skinshifter.SkinShifter;
4-
import dev.tocraft.skinshifter.data.SkinCache;
54
import dev.tocraft.skinshifter.data.SkinPlayerData;
65
import net.fabricmc.api.EnvType;
76
import net.fabricmc.api.Environment;
@@ -25,8 +24,8 @@ public class AbstractClientPlayerMixin {
2524
public void setToNewSkin(CallbackInfoReturnable<PlayerSkin> cir) {
2625
PlayerProfile skin = SkinPlayerData.getSkin((Player) (Object) this);
2726
if (skin != null && skin.skin() != null) {
28-
ResourceLocation skinId = SkinCache.getCustomSkinId(skin.skin());
29-
ResourceLocation capeId = SkinShifter.CONFIG.changeCape ? SkinCache.getCustomCapeId(skin.cape()) : null;
27+
ResourceLocation skinId = skin.getSkinId();
28+
ResourceLocation capeId = SkinShifter.CONFIG.changeCape ? skin.getCapeId() : null;
3029
PlayerSkin.Model model = skin.isSlim() ? PlayerSkin.Model.SLIM : PlayerSkin.Model.WIDE;
3130
PlayerSkin playerSkin = new PlayerSkin(skinId, skin.skin().toString(), capeId, null, model, true);
3231
cir.setReturnValue(playerSkin);
@@ -37,7 +36,7 @@ public void setToNewSkin(CallbackInfoReturnable<PlayerSkin> cir) {
3736
//$$ public void setToNewSkin(CallbackInfoReturnable<ResourceLocation> cir) {
3837
//$$ PlayerProfile skin = SkinPlayerData.getSkin((Player) (Object) this);
3938
//$$ if (skin != null && skin.skin() != null) {
40-
//$$ cir.setReturnValue(SkinCache.getCustomSkinId(skin.skin()));
39+
//$$ cir.setReturnValue(skin.getSkinId());
4140
//$$ }
4241
//$$ }
4342
//$$ @Inject(method = "getModelName", at = @At("RETURN"), cancellable = true)
@@ -52,7 +51,7 @@ public void setToNewSkin(CallbackInfoReturnable<PlayerSkin> cir) {
5251
//$$ if (SkinShifter.CONFIG.changeCape) {
5352
//$$ PlayerProfile skin = SkinPlayerData.getSkin((Player) (Object) this);
5453
//$$ if (skin != null && skin.cape() != null) {
55-
//$$ cir.setReturnValue(SkinCache.getCustomCapeId(skin.cape()));
54+
//$$ cir.setReturnValue(skin.getCapeId());
5655
//$$ }
5756
//$$ }
5857
//$$ }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"skinshifter.command.set": "Setzte den Skin von %s auf den von %s.",
33
"skinshifter.command.reset": "Setzte den Skin von %s zurück.",
4-
"skinshifter.invalid_player": "Ungültiger Spieler-Name: %s",
5-
"skinshifter.config.set": "Config entry %s is now %s",
6-
"skinshifter.config.get": "Config entry %s is set to %s"
4+
"skinshifter.invalid_player": "Ungültiger Spieler-Name: %s"
75
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"skinshifter.command.set": "Set the skin of %s to %s.",
33
"skinshifter.command.reset": "Reset the skin of %s.",
4-
"skinshifter.invalid_player": "Invalid Player Name: %s",
5-
"skinshifter.config.set": "Config entry %s is now %s",
6-
"skinshifter.config.get": "Config entry %s is set to %s"
4+
"skinshifter.invalid_player": "Invalid Player Name: %s"
75
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ maven_group=dev.tocraft
77
# Loader Versions
88
fabric_loader=0.15.11
99
# Dependency Versions
10-
craftedcore_version=5.2
10+
craftedcore_version=5.3
1111
# Upload data
1212
curseforge_id=1076301
1313
modrinth_id=dSkZ41Y3

0 commit comments

Comments
 (0)