mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
refactor creating player component into function
This commit is contained in:
@@ -11,15 +11,14 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||
import net.lionarius.skinrestorer.skin.provider.SkinProvider;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.Translation;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -131,14 +130,7 @@ public final class SkinCommand {
|
||||
}
|
||||
|
||||
if (setByOperator) {
|
||||
var playersComponent = Component.empty();
|
||||
int index = 0;
|
||||
for (var player : updatedPlayers) {
|
||||
playersComponent.append(Objects.requireNonNull(player.getDisplayName()));
|
||||
index++;
|
||||
if (index < updatedPlayers.size())
|
||||
playersComponent.append(", ");
|
||||
}
|
||||
var playersComponent = PlayerUtils.createPlayerListComponent(updatedPlayers);
|
||||
|
||||
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||
Translation.COMMAND_SKIN_AFFECTED_PLAYERS_KEY,
|
||||
@@ -161,4 +153,6 @@ public final class SkinCommand {
|
||||
|
||||
return skinAction(src, Collections.singleton(src.getPlayer().getGameProfile()), false, skinSupplier);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,14 +5,17 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||
import net.lionarius.skinrestorer.mixin.TrackedEntityMixin;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class PlayerUtils {
|
||||
|
||||
@@ -20,6 +23,18 @@ public final class PlayerUtils {
|
||||
|
||||
private PlayerUtils() {}
|
||||
|
||||
public static Component createPlayerListComponent(Collection<ServerPlayer> players) {
|
||||
var component = Component.empty();
|
||||
int index = 0;
|
||||
for (var player : players) {
|
||||
component.append(Objects.requireNonNull(player.getDisplayName()));
|
||||
index++;
|
||||
if (index < players.size())
|
||||
component.append(", ");
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
public static boolean isFakePlayer(ServerPlayer player) {
|
||||
return player.getClass() != ServerPlayer.class; // if the player isn't a server player entity, it must be someone's fake player
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user