FetchProfileCommand.java
net.minecraft.server.commands.FetchProfileCommand
信息
- 全限定名:net.minecraft.server.commands.FetchProfileCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/FetchProfileCommand.java
- 起始行号:L31
- 职责:
TODO
字段/常量
NO_PROFILE- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L36
- 方法名:register
- 源码定位:L36
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static void reportResolvedProfile(CommandSourceStack sender, GameProfile gameProfile, String messageId, Component argument) @ L61
- 方法名:reportResolvedProfile
- 源码定位:L61
- 返回类型:void
- 修饰符:private static
参数:
- sender: CommandSourceStack
- gameProfile: GameProfile
- messageId: String
- argument: Component
说明:
TODO
private static void reportResolvedProfile(CommandSourceStack sender, String messageId, Component argument, ResolvableProfile profile) @ L65
- 方法名:reportResolvedProfile
- 源码定位:L65
- 返回类型:void
- 修饰符:private static
参数:
- sender: CommandSourceStack
- messageId: String
- argument: Component
- profile: ResolvableProfile
说明:
TODO
private static int resolveName(CommandSourceStack source, String name) @ L119
- 方法名:resolveName
- 源码定位:L119
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- name: String
说明:
TODO
private static int resolveId(CommandSourceStack source, UUID id) @ L138
- 方法名:resolveId
- 源码定位:L138
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- id: UUID
说明:
TODO
private static int printForEntity(CommandSourceStack source, Entity entity) @ L157
- 方法名:printForEntity
- 源码定位:L157
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- entity: Entity
说明:
TODO
public static void printForAvatar(CommandSourceStack source, Avatar avatar) @ L166
- 方法名:printForAvatar
- 源码定位:L166
- 返回类型:void
- 修饰符:public static
参数:
- source: CommandSourceStack
- avatar: Avatar
说明:
TODO
代码
public class FetchProfileCommand {
private static final DynamicCommandExceptionType NO_PROFILE = new DynamicCommandExceptionType(
id -> Component.translatableEscape("commands.fetchprofile.no_profile", id)
);
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("fetchprofile")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.literal("name")
.then(
Commands.argument("name", StringArgumentType.greedyString())
.executes(c -> resolveName(c.getSource(), StringArgumentType.getString(c, "name")))
)
)
.then(
Commands.literal("id")
.then(Commands.argument("id", UuidArgument.uuid()).executes(c -> resolveId(c.getSource(), UuidArgument.getUuid(c, "id"))))
)
.then(
Commands.literal("entity")
.then(
Commands.argument("entity", EntityArgument.entity())
.executes(c -> printForEntity(c.getSource(), EntityArgument.getEntity(c, "entity")))
)
)
);
}
private static void reportResolvedProfile(CommandSourceStack sender, GameProfile gameProfile, String messageId, Component argument) {
reportResolvedProfile(sender, messageId, argument, ResolvableProfile.createResolved(gameProfile));
}
private static void reportResolvedProfile(CommandSourceStack sender, String messageId, Component argument, ResolvableProfile profile) {
ResolvableProfile.CODEC
.encodeStart(NbtOps.INSTANCE, profile)
.ifSuccess(
encodedProfile -> {
String encodedProfileAsString = encodedProfile.toString();
MutableComponent headComponent = Component.object(new PlayerSprite(profile, true));
ComponentSerialization.CODEC
.encodeStart(NbtOps.INSTANCE, headComponent)
.ifSuccess(
encodedComponent -> {
String encodedComponentAsString = encodedComponent.toString();
sender.sendSuccess(
() -> {
Component clickable = ComponentUtils.formatList(
List.of(
Component.translatable("commands.fetchprofile.copy_component")
.withStyle(s -> s.withClickEvent(new ClickEvent.CopyToClipboard(encodedProfileAsString))),
Component.translatable("commands.fetchprofile.give_item")
.withStyle(
s -> s.withClickEvent(
new ClickEvent.RunCommand("give @s minecraft:player_head[profile=" + encodedProfileAsString + "]")
)
),
Component.translatable("commands.fetchprofile.summon_mannequin")
.withStyle(
s -> s.withClickEvent(
new ClickEvent.RunCommand(
"summon minecraft:mannequin ~ ~ ~ {profile:" + encodedProfileAsString + "}"
)
)
),
Component.translatable("commands.fetchprofile.copy_text", headComponent.withStyle(ChatFormatting.WHITE))
.withStyle(s -> s.withClickEvent(new ClickEvent.CopyToClipboard(encodedComponentAsString)))
),
CommonComponents.SPACE,
c -> ComponentUtils.wrapInSquareBrackets(c.withStyle(ChatFormatting.GREEN))
);
return Component.translatable(messageId, argument, clickable);
},
false
);
}
)
.ifError(
componentEncodingError -> sender.sendFailure(
Component.translatable("commands.fetchprofile.failed_to_serialize", componentEncodingError.message())
)
);
}
)
.ifError(error -> sender.sendFailure(Component.translatable("commands.fetchprofile.failed_to_serialize", error.message())));
}
private static int resolveName(CommandSourceStack source, String name) {
MinecraftServer server = source.getServer();
ProfileResolver resolver = server.services().profileResolver();
Util.nonCriticalIoPool()
.execute(
() -> {
Component nameComponent = Component.literal(name);
Optional<GameProfile> result = resolver.fetchByName(name);
server.execute(
() -> result.ifPresentOrElse(
profile -> reportResolvedProfile(source, profile, "commands.fetchprofile.name.success", nameComponent),
() -> source.sendFailure(Component.translatable("commands.fetchprofile.name.failure", nameComponent))
)
);
}
);
return 1;
}
private static int resolveId(CommandSourceStack source, UUID id) {
MinecraftServer server = source.getServer();
ProfileResolver resolver = server.services().profileResolver();
Util.nonCriticalIoPool()
.execute(
() -> {
Component idComponent = Component.translationArg(id);
Optional<GameProfile> result = resolver.fetchById(id);
server.execute(
() -> result.ifPresentOrElse(
profile -> reportResolvedProfile(source, profile, "commands.fetchprofile.id.success", idComponent),
() -> source.sendFailure(Component.translatable("commands.fetchprofile.id.failure", idComponent))
)
);
}
);
return 1;
}
private static int printForEntity(CommandSourceStack source, Entity entity) throws CommandSyntaxException {
if (entity instanceof Avatar avatar) {
printForAvatar(source, avatar);
return 1;
} else {
throw NO_PROFILE.create(entity.getDisplayName());
}
}
public static void printForAvatar(CommandSourceStack source, Avatar avatar) {
reportResolvedProfile(source, "commands.fetchprofile.entity.success", avatar.getDisplayName(), avatar.getProfile());
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
EntityArgument.entity(), EntityArgument.getEntity()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
UuidArgument.getUuid(), UuidArgument.uuid()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
ClickEvent.CopyToClipboard(), ClickEvent.RunCommand(), CopyToClipboard(), RunCommand()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Component.literal(), Component.object(), Component.translatable(), Component.translatableEscape(), Component.translationArg()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.formatList(), ComponentUtils.wrapInSquareBrackets()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
PlayerSprite()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.nonCriticalIoPool()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
ResolvableProfile.createResolved()
- 引用位置: