Skip to content

Commit

Permalink
refactor: rename message util
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Jul 15, 2024
1 parent ab820a6 commit d641136
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void registerEnderPlaceholder() {
MessageUtil.ofComponent(player, "display.ender_chest.text")
.hoverEvent(MessageUtil.ofComponent(player, "display.click.prompt"))
.clickEvent(buildDisplayClickEvent(displayUUID));
return PlaceholderResult.value(MessageUtil.toVomponent(replacement));
return PlaceholderResult.value(MessageUtil.toText(replacement));
});
}

Expand All @@ -126,7 +126,7 @@ private void registerInvPlaceholder() {
.hoverEvent(MessageUtil.ofComponent(player, "display.click.prompt"))
.clickEvent(buildDisplayClickEvent(displayUUID));

return PlaceholderResult.value(MessageUtil.toVomponent(replacement));
return PlaceholderResult.value(MessageUtil.toText(replacement));
});
}

Expand All @@ -142,7 +142,7 @@ public void registerItemPlaceholder() {
Component.text("[%s]".formatted(player.getMainHandStack().getName().getString()))
.hoverEvent(MessageUtil.ofComponent(player, "display.click.prompt"))
.clickEvent(buildDisplayClickEvent(displayUUID));
return PlaceholderResult.value(MessageUtil.toVomponent(replacement));
return PlaceholderResult.value(MessageUtil.toText(replacement));
});
}

Expand Down Expand Up @@ -179,7 +179,7 @@ public void registerPosPlaceholder() {
.clickEvent(ClickEvent.runCommand(clickCommand))
.hoverEvent(Component.text(hoverString + "\n").append(MessageUtil.ofComponent(player, "chat.xaero_waypoint_add")));

return PlaceholderResult.value(MessageUtil.toVomponent(component));
return PlaceholderResult.value(MessageUtil.toText(component));
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private boolean hasPermission(ServerPlayerEntity player, Work work) {
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofText(player, "works.list.help"))
.setSkullOwner(GuiUtil.QUESTION_MARK_ICON)
.setLore(MessageUtil.ofVomponents(player, "works.list.help.lore")));
.setLore(MessageUtil.ofTextList(player, "works.list.help.lore")));
gui.setSlot(52, new GuiElementBuilder()
.setItem(Items.COMPASS)
.setName(MessageUtil.ofText(player, "search"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private List<Text> formatSampleCounter(ServerPlayerEntity player) {
double rate = entry.getValue() * ((double) (3600 * 1000) / ((Math.min(this.sample.sampleEndTimeMS, currentTimeMS)) - this.sample.sampleStartTimeMS));
net.kyori.adventure.text.Component component = MessageUtil.ofComponent(player, "works.production_work.prop.sample_counter.entry", entry.getValue(), rate)
.replaceText(TextReplacementConfig.builder().matchLiteral("[item]").replacement(Text.translatable(key)).build());
ret.add(MessageUtil.toVomponent(component));
ret.add(MessageUtil.toText(component));
});

if (ret.isEmpty()) {
Expand All @@ -76,7 +76,7 @@ public List<Text> asLore(ServerPlayerEntity player) {
List<Text> ret = super.asLore(player);
// note: hide sample info in lore if sample not exists
if (this.sample.sampleStartTimeMS == 0) {
ret.addAll((MessageUtil.ofVomponents(player, "works.production_work.sample.not_exists")));
ret.addAll((MessageUtil.ofTextList(player, "works.production_work.sample.not_exists")));
return ret;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public void openSpecializedSettingsGui(ServerPlayerEntity player, SimpleGui pare
gui.addSlot(new GuiElementBuilder()
.setItem(Items.CLOCK)
.setName(MessageUtil.ofText(player, "works.production_work.set.sample"))
.setLore(MessageUtil.ofVomponents(player, "works.production_work.set.sample.lore"))
.setLore(MessageUtil.ofTextList(player, "works.production_work.set.sample.lore"))
.setCallback(() -> new ConfirmGui(player) {
@Override
public void onConfirm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static io.github.sakurawald.util.MessageUtil.ofComponent;
import static io.github.sakurawald.util.MessageUtil.toVomponent;
import static io.github.sakurawald.util.MessageUtil.toText;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerMixin implements AfkStateAccessor {
Expand All @@ -45,7 +45,7 @@ public abstract class ServerPlayerMixin implements AfkStateAccessor {
cir.setReturnValue(Text.literal("afk " + player.getGameProfile().getName()));
net.kyori.adventure.text.@NotNull Component component = ofComponent(null, false,Configs.configHandler.model().modules.afk.format)
.replaceText(TextReplacementConfig.builder().match("%player_display_name%").replacement(player.getDisplayName()).build());
cir.setReturnValue(toVomponent(component));
cir.setReturnValue(toText(component));
} else {
cir.setReturnValue(null);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/sakurawald/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void sendMessageToPlayerEntity(PlayerEntity player, String key, Ob
return ofText(null, false, str, args);
}

public static List<Text> ofVomponents(@Nullable Audience audience, String key, Object... args) {
public static List<Text> ofTextList(@Nullable Audience audience, String key, Object... args) {
String lines = getString(audience, key, args);

List<Text> ret = new ArrayList<>();
Expand All @@ -178,7 +178,7 @@ public static List<Text> ofVomponents(@Nullable Audience audience, String key, O
return ret;
}

public static @NotNull Text toVomponent(Component component) {
public static @NotNull Text toText(Component component) {
return adventure.toNative(component);
}

Expand Down

0 comments on commit d641136

Please sign in to comment.