mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
29 Commits
da754aa830
...
v2.2.0-1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
ebdbee480f
|
|||
|
49b2a2fc1e
|
|||
|
592a6ac253
|
|||
|
33e5889657
|
|||
|
348471b30d
|
|||
|
18ec6e87f8
|
|||
|
e52baaef4c
|
|||
|
03dad0f8dc
|
|||
|
4c803cb369
|
|||
|
120a8b7e3d
|
|||
|
cab2ab3239
|
|||
|
95cc551df7
|
|||
|
3b71911ba0
|
|||
|
7d1d4966b0
|
|||
|
dda9a9632a
|
|||
|
b0d95a4d4f
|
|||
|
14f51e9224
|
|||
|
026ceb2337
|
|||
|
c650aa1386
|
|||
|
1d1aa94644
|
|||
|
3203435453
|
|||
|
8a9802f763
|
|||
|
7add58da44
|
|||
|
5ddde27915
|
|||
|
08b734bb27
|
|||
|
49290171e2
|
|||
|
cfdfee11b3
|
|||
|
5c31b5f881
|
|||
|
b72d0c1e85
|
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@@ -1,90 +0,0 @@
|
||||
name: Bug Report
|
||||
description: Report a bug encountered with SkinRestorer
|
||||
title: "[Bug]: "
|
||||
labels: ["bug"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
🐛 **Before submitting:**
|
||||
- Ensure you're using the latest mod version
|
||||
- Ensure this bug is reproducible consistently
|
||||
- Check existing issues for duplicates
|
||||
|
||||
- type: input
|
||||
id: mod-version
|
||||
attributes:
|
||||
label: SkinRestorer Version
|
||||
description: Exact version of the mod
|
||||
placeholder: e.g., 2.2.1
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: minecraft-version
|
||||
attributes:
|
||||
label: Minecraft Version
|
||||
description: Full Minecraft version
|
||||
placeholder: e.g., 1.21.4
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: loader-version
|
||||
attributes:
|
||||
label: Mod Loader & Version
|
||||
description: Fabric/Quilt/Forge/NeoForge version
|
||||
placeholder: e.g., Fabric 0.15.7
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: java-version
|
||||
attributes:
|
||||
label: Java Version
|
||||
placeholder: e.g. 17, 21
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Bug Description
|
||||
description: What happened vs what you expected to happen
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Reproduction Steps
|
||||
description: Provide step-by-step instructions or a video showing how to reproduce the issue.
|
||||
placeholder: |
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
Or a video demonstrating the issue.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant Logs
|
||||
description: |
|
||||
Please provide any relevant logs, especially error logs from your server console or `latest.log` file.
|
||||
**Important**: Paste the FULL log content. Use a service like [mclo.gs](https://mclo.gs/).
|
||||
render: shell
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: checkboxes
|
||||
id: confirmations
|
||||
attributes:
|
||||
label: Confirmations
|
||||
options:
|
||||
- label: I've checked for existing issues
|
||||
required: true
|
||||
- label: This bug is reproducible consistently
|
||||
required: true
|
||||
- label: I've tested without other mods
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
1
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1 +0,0 @@
|
||||
blank_issues_enabled: true
|
||||
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
@@ -1,52 +0,0 @@
|
||||
name: Feature Request
|
||||
description: Suggest a new feature for SkinRestorer
|
||||
title: "[Feature Request]: "
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
💡 **Before submitting:**
|
||||
- Check existing feature requests for duplicates
|
||||
- Be clear and concise
|
||||
- Explain the *why* and the *how*
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Feature Description
|
||||
description: Detailed description of the feature
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: motivation
|
||||
attributes:
|
||||
label: Motivation
|
||||
description: Why is this feature needed? What problem does it solve?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: use-cases
|
||||
attributes:
|
||||
label: Use Cases
|
||||
description: How would this feature be used and who would benefit?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: implementation-ideas
|
||||
attributes:
|
||||
label: Implementation Ideas (Optional)
|
||||
description: Any thoughts on how it could be implemented?
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: checkboxes
|
||||
id: confirmations
|
||||
attributes:
|
||||
label: Confirmations
|
||||
options:
|
||||
- label: I've checked for existing feature requests
|
||||
required: true
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,4 +30,3 @@ bin/
|
||||
|
||||
.architectury-transformer/
|
||||
run/
|
||||
scripts/
|
||||
|
||||
57
CHANGELOG.md
57
CHANGELOG.md
@@ -4,62 +4,7 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.4.3] - 2025-07-25
|
||||
### Fixed
|
||||
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
||||
- Fixed server freeze when loading player head skin
|
||||
|
||||
## [2.4.2] - 2025-07-13
|
||||
### Fixed
|
||||
- Fix crash when head profile name is null (fixes [#60](https://github.com/Suiranoil/SkinRestorer/issues/60) and [#61](https://github.com/Suiranoil/SkinRestorer/issues/61))
|
||||
|
||||
## [2.4.1] - 2025-07-09
|
||||
### Changed
|
||||
- Log full exception and argument when unable to fetch/set skin
|
||||
### Fixed
|
||||
- Fixed mojang provider using offline uuids when unable to fetch actual uuid resulting in `no profile with uuid` error
|
||||
|
||||
## [2.4.0] - 2025-07-05
|
||||
### Fixed
|
||||
- Added support for player heads
|
||||
|
||||
## [2.3.5] - 2025-06-21
|
||||
### Fixed
|
||||
- Fix mod not loading on client
|
||||
|
||||
## [2.3.4] - 2025-06-19
|
||||
### Added
|
||||
- Added support for minecraft 1.21.6
|
||||
|
||||
## [2.3.3] - 2025-06-01
|
||||
### Fixed
|
||||
- Fixed forge mixin crash (closes [#54](https://github.com/Suiranoil/SkinRestorer/issues/53))
|
||||
### Removed
|
||||
- Removed minecraft 1.19 support
|
||||
|
||||
## [2.3.2] - 2025-05-24
|
||||
### Fixed
|
||||
- Fixed mixin incompatibility with ModernFix (closes [#42](https://github.com/Suiranoil/SkinRestorer/issues/52))
|
||||
|
||||
## [2.3.1] - 2025-05-03
|
||||
### Added
|
||||
- Added support for minecraft 1.19-1.19.4
|
||||
### Changed
|
||||
- Use services and session server urls from environment
|
||||
|
||||
## [2.3.0] - 2025-03-27
|
||||
### Added
|
||||
- Added `skinApplyDelayOnJoin` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#skinapplydelayonjoin))
|
||||
### Changed
|
||||
- Updated to 1.21.5
|
||||
### Removed
|
||||
- [NeoForge] Dropped support for NeoForge on Minecraft 1.20.5-1.20.6
|
||||
|
||||
## [2.2.1] - 2024-12-23
|
||||
### Fixed
|
||||
- Fixed game not closing because of mineskin working threads (closes [#41](https://github.com/Suiranoil/SkinRestorer/issues/41))
|
||||
|
||||
## [2.2.0] - 2024-12-02
|
||||
## [2.2.0] - 2024-11-28
|
||||
### Added
|
||||
- Added support for [SkinShuffle](https://modrinth.com/mod/skinshuffle) clients (requires FabricAPI on Fabric)
|
||||
(closes [#34](https://github.com/Suiranoil/SkinRestorer/issues/34))
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
### Added
|
||||
- Added support for [SkinShuffle](https://modrinth.com/mod/skinshuffle) clients (requires FabricAPI on Fabric)
|
||||
(closes [#34](https://github.com/Suiranoil/SkinRestorer/issues/34))
|
||||
- Added `providers.mineskin.apiKey` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providersmineskin))
|
||||
### Changed
|
||||
- Migrated to MineSkin's new API V2
|
||||
### Fixed
|
||||
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
||||
- Fixed server freeze when loading player head skin
|
||||
- Fixed `providers` config validation
|
||||
### Removed
|
||||
- Dropped support for NeoForge on Minecraft 1.20.2-1.20.4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SkinRestorer
|
||||
|
||||
<a href="https://modrinth.com/mod/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/modrinth/mini/badge.svg" alt="Modrinth"></a>
|
||||
<a href="https://www.curseforge.com/minecraft/mc-mods/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/curseforge/mini/badge.svg" alt="CurseForge"></a>
|
||||
<a href="https://modrinth.com/mod/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/modrinth/mini/badge.svg" alt="Modrinth" height="32"></a>
|
||||
<a href="https://www.curseforge.com/minecraft/mc-mods/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/curseforge/mini/badge.svg" alt="CurseForge" height="32"></a>
|
||||
|
||||
A server-side mod for managing and restoring player skins.
|
||||
|
||||
@@ -33,9 +33,7 @@ the [commands wiki page](https://github.com/Suiranoil/SkinRestorer/wiki/Commands
|
||||
If you enjoy using **SkinRestorer** and would like to support its development, you can contribute through the following
|
||||
platforms:
|
||||
|
||||
<a href="https://ko-fi.com/lionarius"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/donation/kofi/mini/badge.svg" alt="Ko-fi" height="32"></a>
|
||||
|
||||
<a href="https://boosty.to/lionarius"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/donation/boosty/mini/badge.svg" alt="Boosty" height="32"></a>
|
||||
[](https://ko-fi.com/lionarius)
|
||||
|
||||
Bitcoin (BTC): `1Ndbwny8pxdnWXFgadp95fp97y5JqMJKTX`
|
||||
USDT (TRC20): `TGXn8wrqku5KLzwPWQAeH7wgnV4UzwHEae`
|
||||
|
||||
10
build.gradle
10
build.gradle
@@ -1,15 +1,15 @@
|
||||
plugins {
|
||||
// see https://fabricmc.net/develop/ for new versions
|
||||
id 'fabric-loom' version '1.11-SNAPSHOT' apply false
|
||||
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
|
||||
id 'net.neoforged.moddev' version '2.0.+' apply false
|
||||
id 'fabric-loom' version '1.8-SNAPSHOT' apply false
|
||||
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
||||
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
||||
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||
id 'net.minecraftforge.gradle' version '6.0.+' apply false
|
||||
id 'net.minecraftforge.gradle' version '6.0.29' apply false
|
||||
id 'org.parchmentmc.librarian.forgegradle' version '1.+' apply false
|
||||
|
||||
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply false
|
||||
|
||||
id 'me.modmuss50.mod-publish-plugin' version '0.8.+' apply false
|
||||
id 'me.modmuss50.mod-publish-plugin' version '0.8.1' apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
@@ -83,6 +83,7 @@ processResources {
|
||||
'group' : project.group, //Else we target the task's group.
|
||||
'minecraft_version' : minecraft_version,
|
||||
'minecraft_version_range' : minecraft_version_range,
|
||||
'fabric_loader_version' : fabric_loader_version,
|
||||
'mod_name' : mod_name,
|
||||
'mod_author' : mod_author,
|
||||
'mod_id' : mod_id,
|
||||
@@ -91,20 +92,16 @@ processResources {
|
||||
'mod_issues' : mod_issues,
|
||||
'license' : license,
|
||||
'description' : project.description,
|
||||
'forge_version' : forge_version,
|
||||
'forge_loader_version_range' : forge_loader_version_range,
|
||||
'neoforge_version' : neoforge_version,
|
||||
'neoforge_loader_version_range': neoforge_loader_version_range,
|
||||
'credits' : credits,
|
||||
'java_version' : java_version,
|
||||
|
||||
// Loader specific properties
|
||||
'fabric_loader_version' : project.hasProperty('fabric_loader_version') ? fabric_loader_version : '',
|
||||
'forge_version' : project.hasProperty('forge_version') ? forge_version : '',
|
||||
'forge_loader_version_range' : project.hasProperty('forge_loader_version_range') ? forge_loader_version_range : '',
|
||||
'neoforge_version' : project.hasProperty('neoforge_version') ? neoforge_version : '',
|
||||
'neoforge_loader_version_range': project.hasProperty('neoforge_loader_version_range') ? neoforge_loader_version_range : ''
|
||||
'java_version' : java_version
|
||||
]
|
||||
|
||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
||||
expand expandProps
|
||||
}
|
||||
|
||||
inputs.properties(expandProps)
|
||||
}
|
||||
|
||||
@@ -3,17 +3,12 @@ plugins {
|
||||
}
|
||||
|
||||
publishMods {
|
||||
file = project.layout.buildDirectory.file("libs/${project.archivesBaseName}-${project.version}.jar").map { it.asFile }.getOrNull()
|
||||
if (project.name == 'fabric')
|
||||
file = remapJar.archiveFile
|
||||
else
|
||||
file = tasks.named('jarJar').get().archiveFile
|
||||
|
||||
modLoaders.add(project.name)
|
||||
|
||||
if (project.hasProperty('additional_modloaders') && !additional_modloaders.isEmpty())
|
||||
{
|
||||
def loaders = additional_modloaders.split(',')
|
||||
for (loader in loaders)
|
||||
modLoaders.add(loader)
|
||||
}
|
||||
|
||||
type = STABLE
|
||||
version = project.version
|
||||
displayName = "[${project.name.capitalize()}] ${mod_name} ${mod_version}"
|
||||
@@ -28,8 +23,8 @@ publishMods {
|
||||
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||
serverRequired = true
|
||||
|
||||
if (project.hasProperty('optional_dependencies') && !optional_dependencies.isEmpty())
|
||||
optional(optional_dependencies.split(','))
|
||||
if (project.name == 'fabric')
|
||||
optional(fabric_optional_dependencies.split(','))
|
||||
}
|
||||
|
||||
modrinth {
|
||||
@@ -40,7 +35,7 @@ publishMods {
|
||||
|
||||
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||
|
||||
if (project.hasProperty('optional_dependencies') && !optional_dependencies.isEmpty())
|
||||
optional(optional_dependencies.split(','))
|
||||
if (project.name == 'fabric')
|
||||
optional(fabric_optional_dependencies.split(','))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package net.lionarius.skinrestorer;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||
import net.lionarius.skinrestorer.config.Config;
|
||||
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||
import net.lionarius.skinrestorer.mixin.PlayerAccessor;
|
||||
import net.lionarius.skinrestorer.platform.Services;
|
||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||
import net.lionarius.skinrestorer.skin.provider.*;
|
||||
import net.lionarius.skinrestorer.translation.Translation;
|
||||
import net.lionarius.skinrestorer.util.*;
|
||||
import net.lionarius.skinrestorer.util.FileUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -37,8 +37,6 @@ public final class SkinRestorer {
|
||||
private static SkinStorage skinStorage;
|
||||
private static Path configDir;
|
||||
private static Config config;
|
||||
private static TickedScheduler tickedScheduler;
|
||||
private static MinecraftServer minecraftServer;
|
||||
|
||||
private SkinRestorer() {}
|
||||
|
||||
@@ -58,20 +56,12 @@ public final class SkinRestorer {
|
||||
return SkinRestorer.providersRegistry;
|
||||
}
|
||||
|
||||
public static TickedScheduler getTickedScheduler() {
|
||||
return SkinRestorer.tickedScheduler;
|
||||
}
|
||||
|
||||
public static @Nullable MinecraftServer getMinecraftServer() {
|
||||
return SkinRestorer.minecraftServer;
|
||||
}
|
||||
|
||||
public static Optional<SkinProvider> getProvider(String name) {
|
||||
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
|
||||
}
|
||||
|
||||
public static ResourceLocation resourceLocation(String name) {
|
||||
return ResourceLocation.fromNamespaceAndPath(SkinRestorer.MOD_ID, name);
|
||||
return new ResourceLocation(SkinRestorer.MOD_ID, name);
|
||||
}
|
||||
|
||||
public static String assetPath(String name) {
|
||||
@@ -108,44 +98,39 @@ public final class SkinRestorer {
|
||||
MineskinSkinProvider.reload();
|
||||
}
|
||||
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||
var acceptedPlayers = new HashSet<ServerPlayer>();
|
||||
|
||||
for (var player : targets) {
|
||||
var profile = player.getGameProfile();
|
||||
var skin = PlayerUtils.getPlayerSkin(profile);
|
||||
for (var profile : targets) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
||||
value = value.setOriginalValue(skin);
|
||||
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||
continue;
|
||||
|
||||
if (save)
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
|
||||
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
((PlayerAccessor) player).setGameProfile(newProfile);
|
||||
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||
|
||||
if (player.connection == null)
|
||||
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||
if (player == null)
|
||||
continue;
|
||||
|
||||
PlayerUtils.refreshPlayer(player);
|
||||
acceptedPlayers.add(player);
|
||||
|
||||
SkinRestorer.getTickedScheduler().cancel(player.getUUID());
|
||||
}
|
||||
|
||||
return acceptedPlayers;
|
||||
}
|
||||
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value) {
|
||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value) {
|
||||
return SkinRestorer.applySkin(server, targets, value, true);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||
MinecraftServer server,
|
||||
Collection<ServerPlayer> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save
|
||||
) {
|
||||
@@ -158,7 +143,7 @@ public final class SkinRestorer {
|
||||
|
||||
var skinResult = result.get();
|
||||
if (skinResult.isError())
|
||||
throw new TransparentException(Throwables.getRootCause(skinResult.getErrorValue()));
|
||||
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
|
||||
|
||||
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
||||
|
||||
@@ -167,7 +152,7 @@ public final class SkinRestorer {
|
||||
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
|
||||
}, server)
|
||||
.exceptionally(e -> {
|
||||
SkinRestorer.LOGGER.error("Failed to set skin '{}:{}'", context.name(), context.argument(), e);
|
||||
SkinRestorer.LOGGER.error(e.toString());
|
||||
return Result.error(e.getMessage());
|
||||
});
|
||||
}
|
||||
@@ -180,16 +165,6 @@ public final class SkinRestorer {
|
||||
FileUtils.tryMigrateOldSkinDirectory(SkinRestorer.getConfigDir(), worldSkinDirectory);
|
||||
|
||||
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||
SkinRestorer.tickedScheduler = new TickedScheduler(server);
|
||||
server.addTickable(SkinRestorer.tickedScheduler);
|
||||
|
||||
SkinRestorer.minecraftServer = server;
|
||||
}
|
||||
|
||||
public static void onServerStopped(MinecraftServer server) {
|
||||
SkinRestorer.skinStorage = null;
|
||||
SkinRestorer.tickedScheduler = null;
|
||||
SkinRestorer.minecraftServer = null;
|
||||
}
|
||||
|
||||
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.lionarius.skinrestorer.command;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
@@ -17,12 +18,10 @@ import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.NameAndId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -35,7 +34,7 @@ public final class SkinCommand {
|
||||
private SkinCommand() {}
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
var base =
|
||||
LiteralArgumentBuilder<CommandSourceStack> base =
|
||||
literal("skin")
|
||||
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
||||
.then(literal("reset")
|
||||
@@ -45,7 +44,7 @@ public final class SkinCommand {
|
||||
)))
|
||||
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
||||
|
||||
var set = literal("set");
|
||||
LiteralArgumentBuilder<CommandSourceStack> set = literal("set");
|
||||
|
||||
var providers = SkinRestorer.getProvidersRegistry().getPublicProviders();
|
||||
for (var entry : providers)
|
||||
@@ -73,41 +72,37 @@ public final class SkinCommand {
|
||||
|
||||
SkinProviderContext context = null;
|
||||
var save = true;
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||
save = false;
|
||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||
}
|
||||
} else {
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
||||
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
return 0;
|
||||
|
||||
return SkinCommand.setSubcommand(src, Collections.singleton(new NameAndId(profile)), context, save, false);
|
||||
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
||||
}
|
||||
|
||||
private static int resetSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
boolean setByOperator
|
||||
) {
|
||||
var updatedPlayers = new HashSet<ServerPlayer>();
|
||||
for (var nameAndId : targets) {
|
||||
Collection<ServerPlayer> updatedPlayers = new HashSet<>();
|
||||
for (var profile : targets) {
|
||||
SkinValue skin = null;
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||
|
||||
if (skin == null)
|
||||
continue;
|
||||
|
||||
var player = src.getServer().getPlayerList().getPlayer(nameAndId.id());
|
||||
if (player == null)
|
||||
continue;
|
||||
|
||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(player), skin, false);
|
||||
SkinRestorer.getSkinStorage().deleteSkin(nameAndId.id());
|
||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||
|
||||
updatedPlayers.addAll(updatedPlayer);
|
||||
}
|
||||
@@ -123,24 +118,19 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||
}
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean save,
|
||||
boolean setByOperator
|
||||
) {
|
||||
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||
|
||||
var profileTargets = targets.stream()
|
||||
.map(nameAndId -> src.getServer().getPlayerList().getPlayer(nameAndId.id()))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
SkinRestorer.setSkinAsync(src.getServer(), profileTargets, context, save).thenAccept(result -> {
|
||||
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||
if (result.isError()) {
|
||||
src.sendFailure(Translation.translatableWithFallback(
|
||||
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||
@@ -159,7 +149,7 @@ public final class SkinCommand {
|
||||
|
||||
private static int setSubcommand(
|
||||
CommandSourceStack src,
|
||||
Collection<NameAndId> targets,
|
||||
Collection<GameProfile> targets,
|
||||
SkinProviderContext context,
|
||||
boolean setByOperator
|
||||
) {
|
||||
@@ -173,7 +163,7 @@ public final class SkinCommand {
|
||||
if (src.getPlayer() == null)
|
||||
return 0;
|
||||
|
||||
return setSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), context, false);
|
||||
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||
}
|
||||
|
||||
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
||||
@@ -209,7 +199,7 @@ public final class SkinCommand {
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
||||
var action = literal(name);
|
||||
LiteralArgumentBuilder<CommandSourceStack> action = literal(name);
|
||||
|
||||
if (provider.hasVariantSupport()) {
|
||||
for (SkinVariant variant : SkinVariant.values()) {
|
||||
@@ -266,7 +256,7 @@ public final class SkinCommand {
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||
BiFunction<CommandContext<CommandSourceStack>, Collection<NameAndId>, Integer> consumer
|
||||
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
||||
) {
|
||||
return argument("targets", GameProfileArgument.gameProfile())
|
||||
.requires(source -> source.hasPermission(2))
|
||||
|
||||
@@ -24,7 +24,7 @@ public class SkinShuffleCompatibility {
|
||||
}
|
||||
|
||||
public static ResourceLocation resourceLocation(String name) {
|
||||
return ResourceLocation.fromNamespaceAndPath(SkinShuffleCompatibility.MOD_ID, name);
|
||||
return new ResourceLocation(SkinShuffleCompatibility.MOD_ID, name);
|
||||
}
|
||||
|
||||
public static void onPlayerJoin(ServerPlayer player) {
|
||||
@@ -43,7 +43,7 @@ public class SkinShuffleCompatibility {
|
||||
server.execute(() -> {
|
||||
SkinRestorer.applySkin(
|
||||
server,
|
||||
Collections.singleton(player),
|
||||
Collections.singleton(player.getGameProfile()),
|
||||
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
||||
!server.usesAuthentication()
|
||||
);
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleHandshakePayload() implements CustomPacketPayload {
|
||||
|
||||
|
||||
public static final SkinShuffleHandshakePayload INSTANCE = new SkinShuffleHandshakePayload();
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleHandshakePayload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("handshake"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleHandshakePayload> PACKET_CODEC = StreamCodec.unit(INSTANCE);
|
||||
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("handshake");
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomPacketPayload.@NotNull Type<? extends CustomPacketPayload> type() {
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,14 @@ package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleSkinRefreshV1Payload(
|
||||
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV1Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("refresh"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV1Payload> PACKET_CODEC = StreamCodec.of(
|
||||
SkinShuffleSkinRefreshV1Payload::encode,
|
||||
SkinShuffleSkinRefreshV1Payload::decode
|
||||
);
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("refresh");
|
||||
|
||||
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV1Payload value) {
|
||||
var textureProperty = value.textureProperty();
|
||||
@@ -28,7 +24,12 @@ public record SkinShuffleSkinRefreshV1Payload(
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
encode(buf, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,15 @@ package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SkinShuffleSkinRefreshV2Payload(
|
||||
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||
|
||||
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV2Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("skin_refresh"));
|
||||
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV2Payload> PACKET_CODEC = StreamCodec.of(
|
||||
SkinShuffleSkinRefreshV2Payload::encode,
|
||||
SkinShuffleSkinRefreshV2Payload::decode
|
||||
);
|
||||
|
||||
public static final ResourceLocation PACKET_ID = SkinShuffleCompatibility.resourceLocation("skin_refresh");
|
||||
|
||||
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV2Payload value) {
|
||||
var textureProperty = value.textureProperty();
|
||||
|
||||
@@ -27,7 +23,7 @@ public record SkinShuffleSkinRefreshV2Payload(
|
||||
buf.writeUtf(textureProperty.signature());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static SkinShuffleSkinRefreshV2Payload decode(FriendlyByteBuf buf) {
|
||||
if (buf.readBoolean()) {
|
||||
return new SkinShuffleSkinRefreshV2Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readUtf()));
|
||||
@@ -36,7 +32,12 @@ public record SkinShuffleSkinRefreshV2Payload(
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
encode(buf, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation id() {
|
||||
return PACKET_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ public final class Config implements GsonPostProcessable {
|
||||
|
||||
private boolean refreshSkinOnJoin = true;
|
||||
|
||||
private int skinApplyDelayOnJoin = 0;
|
||||
|
||||
private boolean fetchSkinOnFirstJoin = true;
|
||||
|
||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||
@@ -39,10 +37,6 @@ public final class Config implements GsonPostProcessable {
|
||||
return this.refreshSkinOnJoin;
|
||||
}
|
||||
|
||||
public int skinApplyDelayOnJoin() {
|
||||
return this.skinApplyDelayOnJoin;
|
||||
}
|
||||
|
||||
public boolean fetchSkinOnFirstJoin() {
|
||||
return this.fetchSkinOnFirstJoin;
|
||||
}
|
||||
@@ -88,11 +82,6 @@ public final class Config implements GsonPostProcessable {
|
||||
this.language = "en_us";
|
||||
}
|
||||
|
||||
if (this.skinApplyDelayOnJoin < 0) {
|
||||
SkinRestorer.LOGGER.warn("SkinApplyDelayOnJoin config is less than 0, defaulting to 0");
|
||||
this.skinApplyDelayOnJoin = 0;
|
||||
}
|
||||
|
||||
if (this.firstJoinSkinProvider == null) {
|
||||
SkinRestorer.LOGGER.warn("FirstJoinSkinProvider config is null, defaulting to MOJANG");
|
||||
this.firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
package net.lionarius.skinrestorer.config.provider;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
public interface BuiltInProviderConfig {
|
||||
|
||||
public abstract class BuiltInProviderConfig implements GsonPostProcessable {
|
||||
protected boolean enabled;
|
||||
protected String name;
|
||||
protected CacheConfig cache;
|
||||
|
||||
public BuiltInProviderConfig(String name, CacheConfig cache) {
|
||||
this.enabled = true;
|
||||
this.name = name;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CacheConfig cache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
protected void validate(String defaultName, CacheConfig defaultCache) {
|
||||
if (this.name == null || this.name.isEmpty()) {
|
||||
SkinRestorer.LOGGER.warn("Provider name is null or empty, defaulting to '{}'", defaultName);
|
||||
this.name = defaultName;
|
||||
}
|
||||
|
||||
if (this.cache == null) {
|
||||
SkinRestorer.LOGGER.warn("Provider cache is null, using default");
|
||||
this.cache = defaultCache;
|
||||
} else {
|
||||
this.cache.validate(defaultCache);
|
||||
}
|
||||
}
|
||||
boolean enabled();
|
||||
|
||||
String name();
|
||||
|
||||
CacheConfig cache();
|
||||
}
|
||||
|
||||
@@ -5,20 +5,20 @@ import net.lionarius.skinrestorer.SkinRestorer;
|
||||
public final class CacheConfig {
|
||||
private boolean enabled;
|
||||
private long duration;
|
||||
|
||||
|
||||
public CacheConfig(boolean enabled, long duration) {
|
||||
this.enabled = enabled;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
public long duration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
void validate(CacheConfig defaultValue) {
|
||||
if (this.duration <= 0) {
|
||||
SkinRestorer.LOGGER.warn("Cache duration is less than or equal to zero, defaulting to {}", defaultValue.duration());
|
||||
|
||||
@@ -1,16 +1,46 @@
|
||||
package net.lionarius.skinrestorer.config.provider;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
|
||||
public final class ElyByProviderConfig extends BuiltInProviderConfig {
|
||||
public class ElyByProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private CacheConfig cache;
|
||||
|
||||
public ElyByProviderConfig() {
|
||||
super(ElyBySkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
this.enabled = true;
|
||||
this.name = ElyBySkinProvider.PROVIDER_NAME;
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CacheConfig cache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
super.validate(ElyBySkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
if (this.name == null || this.name.isEmpty()) {
|
||||
SkinRestorer.LOGGER.warn("Ely.By provider name is null or empty, defaulting to '{}'", ElyBySkinProvider.PROVIDER_NAME);
|
||||
this.name = ElyBySkinProvider.PROVIDER_NAME;
|
||||
}
|
||||
|
||||
if (this.cache == null) {
|
||||
SkinRestorer.LOGGER.warn("Ely.By provider cache is null, using default");
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
} else {
|
||||
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,52 @@ package net.lionarius.skinrestorer.config.provider;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.provider.MineskinSkinProvider;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
|
||||
public final class MineskinProviderConfig extends BuiltInProviderConfig {
|
||||
public class MineskinProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 300);
|
||||
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private CacheConfig cache;
|
||||
private String apiKey;
|
||||
|
||||
public MineskinProviderConfig() {
|
||||
super(MineskinSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
|
||||
this.enabled = true;
|
||||
this.name = MineskinSkinProvider.PROVIDER_NAME;
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
this.apiKey = "";
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CacheConfig cache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public String apiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
super.validate(MineskinSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
if (this.name == null || this.name.isEmpty()) {
|
||||
SkinRestorer.LOGGER.warn("Mineskin provider name is null or empty, defaulting to '{}'", MineskinSkinProvider.PROVIDER_NAME);
|
||||
this.name = MineskinSkinProvider.PROVIDER_NAME;
|
||||
}
|
||||
|
||||
if (this.cache == null) {
|
||||
SkinRestorer.LOGGER.warn("Mineskin cache is null, using default");
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
} else {
|
||||
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||
}
|
||||
|
||||
if (this.apiKey == null) {
|
||||
SkinRestorer.LOGGER.warn("Mineskin API key is null, defaulting to an empty string");
|
||||
|
||||
@@ -1,16 +1,46 @@
|
||||
package net.lionarius.skinrestorer.config.provider;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
|
||||
public final class MojangProviderConfig extends BuiltInProviderConfig {
|
||||
public class MojangProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private CacheConfig cache;
|
||||
|
||||
public MojangProviderConfig() {
|
||||
super(MojangSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
this.enabled = true;
|
||||
this.name = MojangSkinProvider.PROVIDER_NAME;
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CacheConfig cache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
super.validate(MojangSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||
if (this.name == null || this.name.isEmpty()) {
|
||||
SkinRestorer.LOGGER.warn("Mojang provider name is null or empty, defaulting to '{}'", MojangSkinProvider.PROVIDER_NAME);
|
||||
this.name = MojangSkinProvider.PROVIDER_NAME;
|
||||
}
|
||||
|
||||
if (this.cache == null) {
|
||||
SkinRestorer.LOGGER.warn("Mojang provider cache is null, using default");
|
||||
this.cache = DEFAULT_CACHE_VALUE;
|
||||
} else {
|
||||
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,41 +9,41 @@ public final class ProvidersConfig implements GsonPostProcessable {
|
||||
new ElyByProviderConfig(),
|
||||
new MineskinProviderConfig()
|
||||
);
|
||||
|
||||
|
||||
private MojangProviderConfig mojang;
|
||||
private ElyByProviderConfig ely_by;
|
||||
private MineskinProviderConfig mineskin;
|
||||
|
||||
|
||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
||||
this.mojang = mojang;
|
||||
this.ely_by = ely_by;
|
||||
this.mineskin = mineskin;
|
||||
}
|
||||
|
||||
|
||||
public MojangProviderConfig mojang() {
|
||||
return this.mojang;
|
||||
}
|
||||
|
||||
|
||||
public ElyByProviderConfig ely_by() {
|
||||
return this.ely_by;
|
||||
}
|
||||
|
||||
|
||||
public MineskinProviderConfig mineskin() {
|
||||
return this.mineskin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
if (this.mojang == null) {
|
||||
SkinRestorer.LOGGER.warn("Mojang provider config is null, using default");
|
||||
this.mojang = ProvidersConfig.DEFAULT.mojang();
|
||||
}
|
||||
|
||||
|
||||
if (this.ely_by == null) {
|
||||
SkinRestorer.LOGGER.warn("Ely.By provider config is null, using default");
|
||||
this.ely_by = ProvidersConfig.DEFAULT.ely_by();
|
||||
}
|
||||
|
||||
|
||||
if (this.mineskin == null) {
|
||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package net.lionarius.skinrestorer.exception;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TransparentException extends RuntimeException {
|
||||
public TransparentException(@NotNull Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return this.getCause().getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public class Java11RequestHandler extends RequestHandler {
|
||||
private final Gson gson;
|
||||
private final HttpClient httpClient;
|
||||
|
||||
public Java11RequestHandler(String baseUrl, String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
|
||||
super(baseUrl, userAgent, apiKey, timeout, gson);
|
||||
public Java11RequestHandler(String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
|
||||
super(userAgent, apiKey, timeout, gson);
|
||||
this.gson = gson;
|
||||
|
||||
HttpClient.Builder clientBuilder = HttpClient.newBuilder()
|
||||
@@ -85,7 +85,6 @@ public class Java11RequestHandler extends RequestHandler {
|
||||
|
||||
public <T, R extends MineSkinResponse<T>> R getJson(String url, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||
throws IOException {
|
||||
url = this.baseUrl + url;
|
||||
MineSkinClientImpl.LOGGER.fine("GET " + url);
|
||||
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
@@ -111,7 +110,6 @@ public class Java11RequestHandler extends RequestHandler {
|
||||
|
||||
public <T, R extends MineSkinResponse<T>> R postJson(String url, JsonObject data, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||
throws IOException {
|
||||
url = this.baseUrl + url;
|
||||
MineSkinClientImpl.LOGGER.fine("POST " + url);
|
||||
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
@@ -139,7 +137,6 @@ public class Java11RequestHandler extends RequestHandler {
|
||||
|
||||
public <T, R extends MineSkinResponse<T>> R postFormDataFile(String url, String key, String filename, InputStream in, Map<String, String> data, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||
throws IOException {
|
||||
url = this.baseUrl + url;
|
||||
MineSkinClientImpl.LOGGER.fine("POST " + url);
|
||||
|
||||
String boundary = "mineskin-" + System.currentTimeMillis();
|
||||
|
||||
@@ -9,5 +9,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface ChunkMapAccessor {
|
||||
|
||||
@Accessor
|
||||
Int2ObjectMap<TrackedEntityAccessorInvoker> getEntityMap();
|
||||
Int2ObjectMap<Object> getEntityMap();
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package net.lionarius.skinrestorer.mixin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
|
||||
@Mixin(Player.class)
|
||||
public interface PlayerAccessor {
|
||||
@Accessor("gameProfile")
|
||||
@Mutable
|
||||
void setGameProfile(GameProfile properties);
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -40,23 +39,7 @@ public abstract class PlayerListMixin {
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
|
||||
var delay = SkinRestorer.getConfig().skinApplyDelayOnJoin();
|
||||
|
||||
if (delay <= 0) {
|
||||
skinrestorer$tryApplySkin(server, player);
|
||||
} else {
|
||||
var uuid = player.getUUID();
|
||||
SkinRestorer.getTickedScheduler().schedule(() -> {
|
||||
var actualPlayer = server.getPlayerList().getPlayer(uuid);
|
||||
if (actualPlayer != null)
|
||||
skinrestorer$tryApplySkin(server, actualPlayer);
|
||||
}, delay, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static void skinrestorer$tryApplySkin(MinecraftServer server, ServerPlayer player) {
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||
SkinRestorer.applySkin(server, Collections.singleton(player), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
||||
|
||||
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"),
|
||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||
cancellable = true)
|
||||
public void waitForSkin(CallbackInfo ci) {
|
||||
if (skinrestorer$pendingSkin == null) {
|
||||
@@ -37,14 +37,14 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
assert profile != null;
|
||||
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
||||
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (originalSkin != null) { // update to the latest official skin
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value.setOriginalValue(originalSkin));
|
||||
}
|
||||
|
||||
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
var context = currentSkin.toProviderContext();
|
||||
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -56,7 +56,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||
var context = new SkinProviderContext(
|
||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
||||
profile.name(),
|
||||
profile.getName(),
|
||||
null
|
||||
);
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
@@ -72,7 +72,7 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
@Unique
|
||||
private static void skinrestorer$fetchSkin(GameProfile profile, SkinProviderContext context) {
|
||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.name());
|
||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", profile.getName());
|
||||
|
||||
var result = SkinRestorer.getProvider(context.name()).map(
|
||||
provider -> provider.fetchSkin(context.argument(), context.variant())
|
||||
@@ -80,9 +80,9 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
if (!result.isError()) {
|
||||
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||
} else {
|
||||
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
|
||||
SkinRestorer.LOGGER.warn("Failed to fetch skin: {}", result.getErrorValue().getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import java.util.ServiceLoader;
|
||||
|
||||
public final class Services {
|
||||
|
||||
private Services() {}
|
||||
|
||||
public final static PlatformHelper PLATFORM = load(PlatformHelper.class);
|
||||
public final static CompatibilityHelper COMPATIBILITY = load(CompatibilityHelper.class);
|
||||
|
||||
private Services() {}
|
||||
|
||||
private static <T> T load(Class<T> clazz) {
|
||||
final T loadedService = ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
|
||||
@@ -27,7 +27,9 @@ public class SkinIO {
|
||||
|
||||
public SkinValue loadSkin(UUID uuid) {
|
||||
try {
|
||||
return SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||
var value = SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||
Objects.requireNonNull(value.provider());
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
return SkinValue.EMPTY;
|
||||
}
|
||||
|
||||
@@ -17,22 +17,15 @@ public class SkinStorage {
|
||||
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
|
||||
}
|
||||
|
||||
public SkinValue getSkin(UUID uuid, boolean cache) {
|
||||
public SkinValue getSkin(UUID uuid) {
|
||||
if (!skinMap.containsKey(uuid)) {
|
||||
var skin = skinIO.loadSkin(uuid);
|
||||
if (!cache)
|
||||
return skin;
|
||||
|
||||
setSkin(uuid, skin);
|
||||
}
|
||||
|
||||
return skinMap.get(uuid);
|
||||
}
|
||||
|
||||
public SkinValue getSkin(UUID uuid) {
|
||||
return this.getSkin(uuid, true);
|
||||
}
|
||||
|
||||
public void removeSkin(UUID uuid, boolean save) {
|
||||
var skin = skinMap.remove(uuid);
|
||||
if (skin != null && save)
|
||||
|
||||
@@ -3,14 +3,11 @@ package net.lionarius.skinrestorer.skin;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.lionarius.skinrestorer.skin.provider.EmptySkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
|
||||
@Nullable Property value, @Nullable Property originalValue) implements GsonPostProcessable {
|
||||
@Nullable Property value, @Nullable Property originalValue) {
|
||||
|
||||
public static final SkinValue EMPTY = new SkinValue(EmptySkinProvider.PROVIDER_NAME, null, null, null);
|
||||
|
||||
@@ -33,9 +30,4 @@ public record SkinValue(@NotNull String provider, @Nullable String argument, @Nu
|
||||
public SkinValue setOriginalValue(Property originalValue) {
|
||||
return new SkinValue(this.provider, this.argument, this.variant, this.value, originalValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() {
|
||||
Objects.requireNonNull(this.provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@ import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import net.lionarius.skinrestorer.util.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -71,7 +67,7 @@ public final class ElyBySkinProvider implements SkinProvider {
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
if (!StringUtil.isValidPlayerName(username))
|
||||
if (!StringUtils.isValidPlayerName(username))
|
||||
throw new IllegalArgumentException("invalid username");
|
||||
|
||||
var usernameLowerCase = username.toLowerCase(Locale.ROOT);
|
||||
@@ -106,6 +102,6 @@ public final class ElyBySkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + username);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.mineskin.response.QueueResponse;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -30,10 +31,19 @@ public final class MineskinSkinProvider implements SkinProvider {
|
||||
|
||||
public static final String PROVIDER_NAME = "web";
|
||||
|
||||
private static final URI API_URI;
|
||||
private static MineSkinClient MINESKIN_CLIENT;
|
||||
|
||||
private static LoadingCache<Pair<URI, SkinVariant>, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
static {
|
||||
try {
|
||||
API_URI = new URI("https://api.mineskin.org");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
var config = SkinRestorer.getConfig();
|
||||
var configApiKey = config.providersConfig().mineskin().apiKey();
|
||||
@@ -43,8 +53,7 @@ public final class MineskinSkinProvider implements SkinProvider {
|
||||
.userAgent(WebUtils.USER_AGENT)
|
||||
.gson(JsonUtils.GSON)
|
||||
.timeout((int) Duration.ofSeconds(config.requestTimeout()).toMillis())
|
||||
.requestHandler((baseUrl, userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
|
||||
baseUrl,
|
||||
.requestHandler((userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
|
||||
userAgent,
|
||||
apiKey,
|
||||
timeout,
|
||||
|
||||
@@ -4,21 +4,14 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.mojang.authlib.*;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.authlib.yggdrasil.response.NameAndId;
|
||||
import com.mojang.util.UndashedUuid;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.server.players.CachedUserNameToIdResolver;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import net.lionarius.skinrestorer.util.*;
|
||||
import net.minecraft.server.players.GameProfileCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -32,44 +25,30 @@ import java.util.concurrent.TimeUnit;
|
||||
public final class MojangSkinProvider implements SkinProvider {
|
||||
|
||||
public static final String PROVIDER_NAME = "mojang";
|
||||
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||
private static final Environment ENVIRONMENT;
|
||||
private static final URI SERVICES_SERVER_URI;
|
||||
|
||||
private static final URI API_URI;
|
||||
private static final URI SESSION_SERVER_URI;
|
||||
private static final CachedUserNameToIdResolver PROFILE_CACHE;
|
||||
|
||||
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||
private static final GameProfileCache PROFILE_CACHE;
|
||||
|
||||
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
static {
|
||||
try {
|
||||
ENVIRONMENT = EnvironmentParser.getEnvironmentFromProperties().orElse(YggdrasilEnvironment.PROD.getEnvironment());
|
||||
|
||||
SERVICES_SERVER_URI = new URI(ENVIRONMENT.servicesHost());
|
||||
SESSION_SERVER_URI = new URI(ENVIRONMENT.sessionHost());
|
||||
API_URI = new URI("https://api.mojang.com");
|
||||
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
|
||||
PROFILE_CACHE = new CachedUserNameToIdResolver(new GameProfileRepository() {
|
||||
@Override
|
||||
public void findProfilesByNames(String[] names, ProfileLookupCallback callback) {
|
||||
for (var name : names) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
callback.onProfileLookupSucceeded(profile.name(), profile.id());
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NameAndId> findProfileByName(String name) {
|
||||
PROFILE_CACHE = new GameProfileCache((names, callback) -> {
|
||||
for (var name : names) {
|
||||
try {
|
||||
var profile = MojangSkinProvider.getProfile(name);
|
||||
return Optional.of(new NameAndId(profile.id(), profile.name()));
|
||||
callback.onProfileLookupSucceeded(profile);
|
||||
} catch (IOException e) {
|
||||
throw new TransparentException(e);
|
||||
callback.onProfileLookupFailed(name, e);
|
||||
}
|
||||
}
|
||||
}, SkinRestorer.getConfigDir().resolve(PROFILE_CACHE_FILENAME).toFile());
|
||||
@@ -94,7 +73,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.name(), null);
|
||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,14 +89,14 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
if (!StringUtil.isValidPlayerName(username))
|
||||
if (!StringUtils.isValidPlayerName(username))
|
||||
throw new IllegalArgumentException("invalid username");
|
||||
|
||||
var cachedProfile = MojangSkinProvider.PROFILE_CACHE.get(username);
|
||||
if (cachedProfile.isEmpty())
|
||||
throw new IllegalArgumentException("no profile found for " + username);
|
||||
|
||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().id()));
|
||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().getId()));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
} catch (Exception e) {
|
||||
@@ -132,10 +111,10 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
return Optional.ofNullable(textures);
|
||||
}
|
||||
|
||||
private static NameAndId getProfile(final String name) throws IOException {
|
||||
private static GameProfile getProfile(final String name) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
||||
.resolve("/minecraft/profile/lookup/name/")
|
||||
.uri(MojangSkinProvider.API_URI
|
||||
.resolve("/users/profiles/minecraft/")
|
||||
.resolve(name)
|
||||
)
|
||||
.GET()
|
||||
@@ -147,7 +126,7 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + name);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), NameAndId.class);
|
||||
return JsonUtils.fromJson(response.body(), GameProfile.class);
|
||||
}
|
||||
|
||||
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
||||
@@ -165,6 +144,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
@@ -21,6 +22,7 @@ public final class JsonUtils {
|
||||
.registerTypeAdapterFactory(new PostProcessingEnabler())
|
||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||
.registerTypeAdapter(GameProfile.class, new GameProfile.Serializer())
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||
import net.lionarius.skinrestorer.mixin.TrackedEntityAccessorInvoker;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
@@ -40,7 +39,7 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
public static void refreshPlayer(ServerPlayer player) {
|
||||
ServerLevel serverLevel = player.level();
|
||||
ServerLevel serverLevel = player.serverLevel();
|
||||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||
|
||||
@@ -51,14 +50,14 @@ public final class PlayerUtils {
|
||||
)
|
||||
));
|
||||
|
||||
var trackedEntity = ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||
if (trackedEntity != null) {
|
||||
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
|
||||
for (var observerConnection : seenBy) {
|
||||
var observer = observerConnection.getPlayer();
|
||||
trackedEntity.invokeRemovePlayer(observer);
|
||||
|
||||
var trackedObserverEntity = ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
var trackedObserverEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
if (trackedObserverEntity != null) {
|
||||
trackedObserverEntity.invokeRemovePlayer(player);
|
||||
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||
@@ -68,12 +67,7 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
if (!player.isDeadOrDying()) {
|
||||
player.connection.send(new ClientboundBundlePacket(
|
||||
List.of(
|
||||
new ClientboundRespawnPacket(player.createCommonSpawnInfo(serverLevel), ClientboundRespawnPacket.KEEP_ALL_DATA),
|
||||
new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0)
|
||||
)
|
||||
));
|
||||
player.connection.send(new ClientboundRespawnPacket(player.createCommonSpawnInfo(serverLevel), ClientboundRespawnPacket.KEEP_ALL_DATA));
|
||||
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
player.connection.send(new ClientboundSetEntityMotionPacket(player));
|
||||
var vehicle = player.getVehicle();
|
||||
@@ -87,37 +81,25 @@ public final class PlayerUtils {
|
||||
playerList.sendPlayerPermissionLevel(player);
|
||||
playerList.sendLevelInfo(player, serverLevel);
|
||||
playerList.sendAllPlayerInfo(player);
|
||||
playerList.sendActivePlayerEffects(player);
|
||||
PlayerUtils.sendActivePlayerEffects(player);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendActivePlayerEffects(ServerPlayer player) {
|
||||
for (var effect : player.getActiveEffects()) {
|
||||
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect, false));
|
||||
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect));
|
||||
}
|
||||
}
|
||||
|
||||
public static GameProfile cloneGameProfile(GameProfile profile) {
|
||||
var newProfile = new GameProfile(profile.id(), profile.name());
|
||||
newProfile.properties().putAll(profile.properties());
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(GameProfile profile) {
|
||||
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
||||
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||
}
|
||||
|
||||
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
var propertiesMap = profile.properties();
|
||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||
|
||||
var newProperties = LinkedHashMultimap.create(propertiesMap);
|
||||
newProperties.removeAll(TEXTURES_KEY);
|
||||
if (skin != null) {
|
||||
newProperties.put(TEXTURES_KEY, skin);
|
||||
}
|
||||
|
||||
return new GameProfile(profile.id(), profile.name(), new PropertyMap(newProperties));
|
||||
if (skin != null)
|
||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||
}
|
||||
|
||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||
@@ -141,7 +123,7 @@ public final class PlayerUtils {
|
||||
|
||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||
profile.properties().putAll(response.properties());
|
||||
profile.getProperties().putAll(response.properties());
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@ public class Result<S, E> {
|
||||
this.errorValue = errorValue;
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||
return new Result<>(successValue, null);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||
return new Result<>(null, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||
return Result.success(Optional.ofNullable(successValue));
|
||||
}
|
||||
|
||||
public S getSuccessValue() {
|
||||
return successValue;
|
||||
}
|
||||
@@ -81,4 +69,16 @@ public class Result<S, E> {
|
||||
public int hashCode() {
|
||||
return Objects.hash(successValue, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||
return new Result<>(successValue, null);
|
||||
}
|
||||
|
||||
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||
return new Result<>(null, errorValue);
|
||||
}
|
||||
|
||||
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||
return Result.success(Optional.ofNullable(successValue));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
public class TickedScheduler implements Runnable {
|
||||
private final MinecraftServer server;
|
||||
private final Queue<TickTask> queue = new PriorityBlockingQueue<>();
|
||||
private final Map<Integer, Integer> idMap = new ConcurrentHashMap<>();
|
||||
|
||||
public TickedScheduler(MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void schedule(Runnable task, int delay) {
|
||||
this.schedule(task, delay, task);
|
||||
}
|
||||
|
||||
public void schedule(Runnable task, int delay, Object id) {
|
||||
var taskId = id.hashCode();
|
||||
var serverTick = this.server.getTickCount();
|
||||
this.idMap.merge(taskId, serverTick, Integer::max);
|
||||
this.queue.add(new TickTask(serverTick, serverTick + delay, taskId, task));
|
||||
}
|
||||
|
||||
public void cancel(Object id) {
|
||||
var taskId = id.hashCode();
|
||||
this.idMap.remove(taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
TickTask nextTask;
|
||||
while ((nextTask = this.queue.peek()) != null) {
|
||||
if (nextTask.runOnTick() > this.server.getTickCount())
|
||||
break;
|
||||
|
||||
var tickTask = this.queue.remove();
|
||||
var lastTaskScheduledOnTick = this.idMap.get(tickTask.id());
|
||||
|
||||
if (lastTaskScheduledOnTick != null && lastTaskScheduledOnTick <= tickTask.scheduledOnTick()) {
|
||||
this.idMap.remove(tickTask.id());
|
||||
if (tickTask.task() != null)
|
||||
tickTask.task().run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record TickTask(int scheduledOnTick, int runOnTick, int id, Runnable task) implements Comparable<TickTask> {
|
||||
@Override
|
||||
public int compareTo(@NotNull TickedScheduler.TickTask other) {
|
||||
return Integer.compare(this.runOnTick, other.runOnTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
public final class WebUtils {
|
||||
|
||||
private WebUtils() {}
|
||||
|
||||
public static final String USER_AGENT;
|
||||
|
||||
private static HttpClient HTTP_CLIENT = null;
|
||||
@@ -21,8 +23,6 @@ public final class WebUtils {
|
||||
USER_AGENT = String.format("SkinRestorer/%d", System.currentTimeMillis() % 65535);
|
||||
}
|
||||
|
||||
private WebUtils() {}
|
||||
|
||||
public static void recreateHttpClient() {
|
||||
HTTP_CLIENT = WebUtils.buildClient();
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
accessWidener v2 named
|
||||
@@ -2,15 +2,13 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.lionarius.skinrestorer.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"priority": 1100,
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"mixins": [
|
||||
"ChunkMapAccessor",
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"TrackedEntityAccessorInvoker",
|
||||
"PlayerAccessor"
|
||||
"TrackedEntityAccessorInvoker"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||
fabric_loader_version=0.15.0
|
||||
fabric_api_version=0.133.14+1.21.9
|
||||
|
||||
optional_dependencies=fabric-api
|
||||
additional_modloaders=quilt
|
||||
@@ -1,14 +1,17 @@
|
||||
package net.lionarius.skinrestorer.fabric.compat.skinshuffle;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshPayload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV1Payload;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV2Payload;
|
||||
import net.lionarius.skinrestorer.fabric.SkinRestorerFabric;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
|
||||
@@ -20,18 +23,24 @@ public final class SkinShuffleCompatibility {
|
||||
return;
|
||||
}
|
||||
|
||||
PayloadTypeRegistry.playS2C().register(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC);
|
||||
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.onPlayerJoin(handler.getPlayer()));
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV1Packet);
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshV2Packet);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, ServerPlayNetworking.Context context) {
|
||||
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), context.player(), payload);
|
||||
private static void handleSkinRefreshV1Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(buf);
|
||||
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshV2Packet(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl listener, FriendlyByteBuf buf, PacketSender sender) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(buf);
|
||||
SkinShuffleCompatibility.handleSkinRefreshPacket(payload, server, player);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, MinecraftServer server, ServerPlayer player) {
|
||||
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(server, player, payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class MinecraftServerMixin {
|
||||
|
||||
@Inject(method = "runServer",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getMillis()J", ordinal = 0))
|
||||
private void onServerStarted(CallbackInfo ci) {
|
||||
SkinRestorer.Events.onServerStarted((MinecraftServer) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "runServer",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;onServerExit()V"))
|
||||
private void onServerStopped(CallbackInfo ci) {
|
||||
SkinRestorer.Events.onServerStopped((MinecraftServer) (Object) this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.lionarius.skinrestorer.fabric.platform;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
|
||||
@@ -8,6 +9,6 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
public final class FabricCompatibilityHelper implements CompatibilityHelper {
|
||||
@Override
|
||||
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||
ServerPlayNetworking.send(player, SkinShuffleHandshakePayload.INSTANCE);
|
||||
ServerPlayNetworking.send(player, SkinShuffleHandshakePayload.PACKET_ID, PacketByteBufs.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
"${mod_id}.mixins.json",
|
||||
"${mod_id}.fabric.mixins.json"
|
||||
],
|
||||
"accessWidener": "${mod_id}.accesswidener",
|
||||
"depends": {
|
||||
"fabricloader": ">=${fabric_loader_version}",
|
||||
"minecraft": ">=${minecraft_version}",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "net.lionarius.skinrestorer.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"mixins": [
|
||||
"CommandsMixin",
|
||||
|
||||
@@ -17,33 +17,32 @@ mixin {
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
tasks.named('jar') {
|
||||
archiveClassifier = 'thin'
|
||||
}
|
||||
|
||||
tasks.named('jarJar') {
|
||||
archiveClassifier = ''
|
||||
}
|
||||
|
||||
jar.finalizedBy('jarJar')
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'parchment', version: "${parchment_minecraft}-${parchment_version}-${minecraft_version}"
|
||||
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
||||
|
||||
copyIdeResources = true //Calls processResources when in dev
|
||||
|
||||
reobf = false // Forge 1.20.6+ uses official mappings at runtime, so we shouldn't reobf from official to SRG
|
||||
|
||||
// Automatically enable forge AccessTransformers if the file exists
|
||||
// This location is hardcoded in Forge and can not be changed.
|
||||
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
|
||||
def at = project(":common").file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
if (at.exists()) {
|
||||
accessTransformer = at
|
||||
}
|
||||
|
||||
runs {
|
||||
client {
|
||||
workingDirectory rootProject.file('run/client')
|
||||
workingDirectory file('../run/client')
|
||||
ideaModule "${rootProject.name}.${project.name}.main"
|
||||
taskName 'Client'
|
||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
||||
mods {
|
||||
modClientRun {
|
||||
source sourceSets.main
|
||||
@@ -52,10 +51,9 @@ minecraft {
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory rootProject.file('run/server')
|
||||
workingDirectory file('../run/server')
|
||||
ideaModule "${rootProject.name}.${project.name}.main"
|
||||
taskName 'Server'
|
||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
||||
mods {
|
||||
modServerRun {
|
||||
source sourceSets.main
|
||||
@@ -68,8 +66,6 @@ minecraft {
|
||||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
||||
|
||||
annotationProcessor('net.minecraftforge:eventbus-validator:7.0-beta.7')
|
||||
|
||||
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
||||
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
||||
|
||||
@@ -92,7 +88,3 @@ sourceSets.each {
|
||||
it.output.resourcesDir = dir
|
||||
it.java.destinationDirectory = dir
|
||||
}
|
||||
|
||||
tasks.named('processResources') {
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||
forge_version=59.0.0
|
||||
forge_loader_version_range=[59,)
|
||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||
forge_minecraft_version=1.21.9
|
||||
@@ -4,8 +4,7 @@ import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||
import net.minecraftforge.eventbus.api.listener.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod(SkinRestorer.MOD_ID)
|
||||
@@ -28,9 +27,4 @@ public final class SkinRestorerForge {
|
||||
public static void onServerStarted(ServerStartedEvent event) {
|
||||
SkinRestorer.Events.onServerStarted(event.getServer());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStopped(ServerStoppedEvent event) {
|
||||
SkinRestorer.Events.onServerStopped(event.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
|
||||
private SkinShuffleCompatibility() {}
|
||||
|
||||
public static void initialize() {
|
||||
PlayerEvent.PlayerLoggedInEvent.BUS.addListener(SkinShuffleGameEventHandler::onPlayerLoggedIn);
|
||||
MinecraftForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||
|
||||
SkinShufflePacketHandler.initialize();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public final class SkinShuffleGameEventHandler {
|
||||
|
||||
private SkinShuffleGameEventHandler() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
|
||||
}
|
||||
|
||||
@@ -1,45 +1,59 @@
|
||||
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||
import net.minecraftforge.network.Channel;
|
||||
import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.EventNetworkChannel;
|
||||
|
||||
public class SkinShufflePacketHandler {
|
||||
private static final Channel<CustomPacketPayload> INSTANCE = ChannelBuilder
|
||||
.named(SkinRestorer.resourceLocation("skin_shuffle_compat"))
|
||||
.optional()
|
||||
.payloadChannel()
|
||||
.any()
|
||||
.clientbound()
|
||||
.add(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC, (payload, context) -> {
|
||||
})
|
||||
.serverbound()
|
||||
.add(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
||||
.add(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
||||
.build();
|
||||
|
||||
private SkinShufflePacketHandler() {
|
||||
}
|
||||
|
||||
private static final EventNetworkChannel HANDSHAKE_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel()
|
||||
.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
|
||||
.optional()
|
||||
.eventNetworkChannel()
|
||||
.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
|
||||
|
||||
protected static void initialize() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
|
||||
public static void sendHandshake(Connection connection) {
|
||||
INSTANCE.send(SkinShuffleHandshakePayload.INSTANCE, connection);
|
||||
HANDSHAKE_INSTANCE.send(new FriendlyByteBuf(Unpooled.buffer(0, 0)), connection);
|
||||
}
|
||||
|
||||
private static void skinRefreshV1Listener(CustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void skinRefreshV2Listener(CustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, CustomPayloadEvent.Context context) {
|
||||
var sender = context.getSender();
|
||||
|
||||
if (!context.isServerSide() || sender == null)
|
||||
return;
|
||||
|
||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), sender, payload);
|
||||
SkinShuffleCompatibility.handleSkinRefresh(sender.getServer(), sender, payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# Project
|
||||
group=net.lionarius
|
||||
java_version=21
|
||||
java_version=17
|
||||
|
||||
# Common
|
||||
minecraft_version=1.21.9
|
||||
minecraft_version_list=1.21.9
|
||||
minecraft_version_range=[1.21.9, 1.22)
|
||||
minecraft_version=1.20.2
|
||||
minecraft_version_list=1.20.2
|
||||
minecraft_version_range=1.20.2
|
||||
mod_id=skinrestorer
|
||||
mod_name=SkinRestorer
|
||||
mod_version=2.4.3
|
||||
mod_version=2.2.0
|
||||
mod_author=Lionarius
|
||||
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||
@@ -17,12 +17,26 @@ license=MIT
|
||||
credits=
|
||||
description=A server-side mod for managing skins.
|
||||
|
||||
# Dependencies
|
||||
mineskin_client_version=3.0.6-SNAPSHOT
|
||||
mineskin_client_version=3.0.1-SNAPSHOT
|
||||
|
||||
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||
parchment_minecraft=1.21.8
|
||||
parchment_version=2025.09.14
|
||||
parchment_minecraft=1.20.2
|
||||
parchment_version=2023.12.10
|
||||
|
||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||
fabric_loader_version=0.15.0
|
||||
fabric_api_version=0.91.1+1.20.3
|
||||
fabric_optional_dependencies=fabric-api
|
||||
|
||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||
forge_version=48.0.0
|
||||
forge_loader_version_range=[48,)
|
||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||
forge_minecraft_version=1.20.2
|
||||
|
||||
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
||||
neoforge_version=20.2.3-beta
|
||||
neoforge_loader_version_range=[1,)
|
||||
|
||||
# Publishing
|
||||
curseforge_id=443823
|
||||
@@ -31,5 +45,3 @@ modrinth_id=ghrZDhGW
|
||||
# Gradle
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
9
gradlew
vendored
9
gradlew
vendored
@@ -86,7 +86,8 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -114,7 +115,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -205,7 +206,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -213,7 +214,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
4
gradlew.bat
vendored
4
gradlew.bat
vendored
@@ -70,11 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -3,56 +3,56 @@ plugins {
|
||||
id 'idea'
|
||||
id 'eclipse'
|
||||
|
||||
id 'net.neoforged.moddev'
|
||||
id 'net.neoforged.gradle.userdev'
|
||||
|
||||
id 'multiloader-publish'
|
||||
}
|
||||
|
||||
neoForge {
|
||||
version = neoforge_version
|
||||
|
||||
// Automatically enable neoforge AccessTransformers if the file exists
|
||||
def at = project(":common").file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
if (at.exists()) {
|
||||
accessTransformers.from(at.absolutePath)
|
||||
}
|
||||
|
||||
parchment {
|
||||
minecraftVersion = parchment_minecraft
|
||||
mappingsVersion = parchment_version
|
||||
}
|
||||
|
||||
runs {
|
||||
configureEach {
|
||||
ideName = "NeoForge ${it.name.capitalize()} (${project.path})" // Unify the run config names with fabric
|
||||
}
|
||||
|
||||
client {
|
||||
client()
|
||||
gameDirectory = rootProject.file('run/client')
|
||||
}
|
||||
|
||||
server {
|
||||
server()
|
||||
programArgument '--nogui'
|
||||
gameDirectory = rootProject.file('run/server')
|
||||
}
|
||||
}
|
||||
|
||||
mods {
|
||||
"${mod_id}" {
|
||||
sourceSet sourceSets.main
|
||||
}
|
||||
}
|
||||
// Automatically enable neoforge AccessTransformers if the file exists
|
||||
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
if (at.exists()) {
|
||||
minecraft.accessTransformers.file(at)
|
||||
}
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
tasks.named('jar') {
|
||||
archiveClassifier = 'thin'
|
||||
}
|
||||
|
||||
tasks.named('jarJar') {
|
||||
archiveClassifier = ''
|
||||
}
|
||||
|
||||
jar.finalizedBy('jarJar')
|
||||
|
||||
dependencies {
|
||||
implementation "net.neoforged:neoforge:${neoforge_version}"
|
||||
|
||||
jarJar(implementation('org.mineskin:java-client')) {
|
||||
version {
|
||||
strictly "[${mineskin_client_version},)"
|
||||
prefer mineskin_client_version
|
||||
}
|
||||
implementation(jarJar(group: 'org.mineskin', name: 'java-client', version: mineskin_client_version)) {
|
||||
jarJar.ranged(it, "[${mineskin_client_version},)")
|
||||
}
|
||||
}
|
||||
|
||||
subsystems {
|
||||
parchment {
|
||||
minecraftVersion = parchment_minecraft
|
||||
mappingsVersion = parchment_version
|
||||
}
|
||||
}
|
||||
|
||||
runs {
|
||||
configureEach {
|
||||
modSource project.sourceSets.main
|
||||
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
|
||||
}
|
||||
|
||||
client {
|
||||
workingDirectory = file('../run/client')
|
||||
}
|
||||
|
||||
server {
|
||||
programArgument '--nogui'
|
||||
workingDirectory = file('../run/server')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
||||
neoforge_version=21.9.0-beta
|
||||
neoforge_loader_version_range=[4,)
|
||||
@@ -3,14 +3,12 @@ package net.lionarius.skinrestorer.neoforge;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||
|
||||
@Mod(SkinRestorer.MOD_ID)
|
||||
@EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||
public final class SkinRestorerNeoForge {
|
||||
|
||||
public SkinRestorerNeoForge() {
|
||||
@@ -29,9 +27,4 @@ public final class SkinRestorerNeoForge {
|
||||
public static void onServerStarted(ServerStartedEvent event) {
|
||||
SkinRestorer.Events.onServerStarted(event.getServer());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStopped(ServerStoppedEvent event) {
|
||||
SkinRestorer.Events.onServerStopped(event.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
public final class SkinShuffleCompatibility {
|
||||
@@ -11,7 +9,6 @@ public final class SkinShuffleCompatibility {
|
||||
public static void initialize() {
|
||||
NeoForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||
|
||||
final var mod = ModList.get().getModContainerById(SkinRestorer.MOD_ID).get();
|
||||
mod.getEventBus().register(SkinShuffleModEventHandler.class);
|
||||
SkinShufflePacketHandler.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.registration.HandlerThread;
|
||||
|
||||
public final class SkinShuffleModEventHandler {
|
||||
private SkinShuffleModEventHandler() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterPayloadHandlers(RegisterPayloadHandlersEvent event) {
|
||||
final var registrar = event.registrar("1").optional().executesOn(HandlerThread.NETWORK);
|
||||
|
||||
registrar
|
||||
.playToClient(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC,
|
||||
(payload, context) -> {})
|
||||
.playToServer(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC,
|
||||
SkinShuffleModEventHandler::handleSkinRefreshPacket)
|
||||
.playToServer(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC,
|
||||
SkinShuffleModEventHandler::handleSkinRefreshPacket);
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
||||
var player = (ServerPlayer) context.player();
|
||||
SkinShuffleCompatibility.handleSkinRefresh(SkinRestorer.getMinecraftServer(), player, payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||
import net.neoforged.neoforge.network.NetworkConstants;
|
||||
import net.neoforged.neoforge.network.NetworkEvent;
|
||||
import net.neoforged.neoforge.network.NetworkRegistry;
|
||||
import net.neoforged.neoforge.network.event.EventNetworkChannel;
|
||||
|
||||
public final class SkinShufflePacketHandler {
|
||||
private SkinShufflePacketHandler() {
|
||||
}
|
||||
|
||||
// there is no need for handshake channel but register it to not allow other mods to use it
|
||||
private static final EventNetworkChannel HANDSHAKE_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleHandshakePayload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.networkProtocolVersion(() -> NetworkConstants.NETVERSION)
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V1_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV1Payload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.networkProtocolVersion(() -> NetworkConstants.NETVERSION)
|
||||
.eventNetworkChannel();
|
||||
|
||||
private static final EventNetworkChannel SKIN_REFRESH_V2_INSTANCE = NetworkRegistry.ChannelBuilder
|
||||
.named(SkinShuffleSkinRefreshV2Payload.PACKET_ID)
|
||||
.serverAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.clientAcceptedVersions(NetworkRegistry.acceptMissingOr("1"))
|
||||
.networkProtocolVersion(() -> NetworkConstants.NETVERSION)
|
||||
.eventNetworkChannel();
|
||||
|
||||
static void initialize() {
|
||||
SKIN_REFRESH_V1_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV1Listener);
|
||||
SKIN_REFRESH_V2_INSTANCE.addListener(SkinShufflePacketHandler::skinRefreshV2Listener);
|
||||
}
|
||||
|
||||
private static void skinRefreshV1Listener(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV1Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void skinRefreshV2Listener(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
var payload = SkinShuffleSkinRefreshV2Payload.decode(event.getPayload());
|
||||
handleSkinRefreshPacket(payload, event.getSource());
|
||||
}
|
||||
|
||||
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, NetworkEvent.Context context) {
|
||||
var player = context.getSender();
|
||||
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,6 @@ public final class NeoForgeCompatibilityHelper implements CompatibilityHelper {
|
||||
@Override
|
||||
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||
// we can't use the packet distributor here because neoforge doesn't support sending packets to non-neoforge players
|
||||
player.connection.getConnection().send(new ClientboundCustomPayloadPacket(SkinShuffleHandshakePayload.INSTANCE));
|
||||
player.connection.connection.send(new ClientboundCustomPayloadPacket(SkinShuffleHandshakePayload.INSTANCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ config = "${mod_id}.mixins.json"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "neoforge"
|
||||
type = "required"
|
||||
mandatory = true
|
||||
versionRange = "[${neoforge_version},)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "minecraft"
|
||||
type = "required"
|
||||
mandatory = true
|
||||
versionRange = "${minecraft_version_range}"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
@@ -71,4 +71,4 @@ rootProject.name = 'skin-restorer'
|
||||
include('common')
|
||||
include('fabric')
|
||||
include('forge')
|
||||
include('neoforge')
|
||||
//include('neoforge')
|
||||
|
||||
Reference in New Issue
Block a user