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 75904cf commit ab820a6
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {

afk_player.fuji$setAfk(true);
if (Configs.configHandler.model().modules.afk.afk_checker.kick_player) {
player.networkHandler.disconnect(MessageUtil.ofVomponent(player, "afk.kick"));
player.networkHandler.disconnect(MessageUtil.ofText(player, "afk.kick"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void registerSuffixPlaceholder() {

ServerPlayerEntity player = ctx.player();
String prefix = LuckPermsUtil.getPrefix(player);
return PlaceholderResult.value(MessageUtil.ofVomponent(prefix));
return PlaceholderResult.value(MessageUtil.ofText(prefix));
});
}

Expand All @@ -204,7 +204,7 @@ private void registerPrefixPlaceholder() {

ServerPlayerEntity player = ctx.player();
String prefix = LuckPermsUtil.getPrefix(player);
return PlaceholderResult.value(MessageUtil.ofVomponent(prefix));
return PlaceholderResult.value(MessageUtil.ofText(prefix));
});
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public Text parseText(ServerPlayerEntity player, String message) {

/* combine */
String string = format.replace("%message%", message);
return MessageUtil.ofVomponent(player, false, string);
return MessageUtil.ofText(player, false, string);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class DisplayHelper {
private static final SoftReferenceMap<String, DisplayGuiBuilder> uuid2gui = new SoftReferenceMap<>();

public static String createInventoryDisplay(@NotNull ServerPlayerEntity player) {
Text title = MessageUtil.ofVomponent(player, "display.gui.title", player.getGameProfile().getName());
Text title = MessageUtil.ofText(player, "display.gui.title", player.getGameProfile().getName());
String uuid = UUID.randomUUID().toString();
uuid2gui.put(uuid, new InventoryDisplayGui(title, player));
return uuid;
}

public static String createEnderChestDisplay(@NotNull ServerPlayerEntity player) {
Text title = MessageUtil.ofVomponent(player, "display.gui.title", player.getGameProfile().getName());
Text title = MessageUtil.ofText(player, "display.gui.title", player.getGameProfile().getName());
String uuid = UUID.randomUUID().toString();
uuid2gui.put(uuid, new EnderChestDisplayGui(title, player));
return uuid;
Expand All @@ -31,7 +31,7 @@ public static String createEnderChestDisplay(@NotNull ServerPlayerEntity player)
public static String createItemDisplay(@NotNull ServerPlayerEntity player) {
/* new object */
DisplayGuiBuilder displayGuiBuilder;
Text title = MessageUtil.ofVomponent(player, "display.gui.title", player.getGameProfile().getName());
Text title = MessageUtil.ofText(player, "display.gui.title", player.getGameProfile().getName());
ItemStack itemStack = player.getMainHandStack().copy();
if (DisplayGuiBuilder.isShulkerBox(itemStack)) {
// shulker-box item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class DisplayGuiBuilder {
protected static void $setSlot(SimpleGui gui, int i, ItemStack itemStack, SlotClickForDeeperDisplayCallback slotClickForDeeperDisplayCallback) {
GuiElementBuilder guiElementBuilder = GuiElementBuilder.from(itemStack).setCallback(slotClickForDeeperDisplayCallback);
if (isShulkerBox(itemStack)) {
guiElementBuilder.addLoreLine(MessageUtil.ofVomponent(gui.getPlayer(), "display.click.prompt"));
guiElementBuilder.addLoreLine(MessageUtil.ofText(gui.getPlayer(), "display.click.prompt"));
}
gui.setSlot(i, guiElementBuilder.build());
}
Expand All @@ -35,7 +35,7 @@ protected record SlotClickForDeeperDisplayCallback(SimpleGui parentGui,
public void click(int i, ClickType clickType, net.minecraft.screen.slot.SlotActionType clickType1, SlotGuiInterface slotGuiInterface) {
ItemStack itemStack = slotGuiInterface.getSlot(i).getItemStack();
if (isShulkerBox(itemStack)) {
ShulkerBoxDisplayGui shulkerBoxDisplayGui = new ShulkerBoxDisplayGui(MessageUtil.ofVomponent(player, "display.gui.title", player.getGameProfile().getName()), itemStack, parentGui);
ShulkerBoxDisplayGui shulkerBoxDisplayGui = new ShulkerBoxDisplayGui(MessageUtil.ofText(player, "display.gui.title", player.getGameProfile().getName()), itemStack, parentGui);
shulkerBoxDisplayGui.build(player).open();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import io.github.sakurawald.util.MessageUtil;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -41,7 +39,7 @@ public SimpleGui build(ServerPlayerEntity player) {
if (this.parentGui != null) {
gui.setSlot(LINE_SIZE - 1, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "back"))
.setName(MessageUtil.ofText(player, "back"))
.setSkullOwner(GuiUtil.PREVIOUS_PAGE_ICON)
.setCallback(parentGui::open));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public ItemStack of(ServerPlayerEntity player) {
}

public Text getDisplayName(ServerPlayerEntity player) {
return MessageUtil.ofVomponent(player, "head.category." + name);
return MessageUtil.ofText(player, "head.category." + name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public HeadGui(ServerPlayerEntity player) {
addCategoryButton(index, category);
++index;
}
this.setTitle(MessageUtil.ofVomponent(player, "head.title"));
this.setTitle(MessageUtil.ofText(player, "head.title"));
this.setSlot(this.getSize() - 1, new GuiElementBuilder()
.setItem(Items.COMPASS)
.setName(MessageUtil.ofVomponent(player, "search"))
.setName(MessageUtil.ofText(player, "search"))
.setCallback((index1, type1, action) -> new SearchInputGui(this).open()));
this.setSlot(this.getSize() - 2, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "head.category.player"))
.setName(MessageUtil.ofText(player, "head.category.player"))
.setCallback((index1, type1, action) -> new PlayerInputGui(this).open()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void updateNavigation() {
}

navigationLayer.setSlot(
3, new GuiElementBuilder().setItem(Items.PLAYER_HEAD).setName(MessageUtil.ofVomponent(parent.getPlayer(), "previous_page")).setSkullOwner(GuiUtil.PREVIOUS_PAGE_ICON).asStack(),
3, new GuiElementBuilder().setItem(Items.PLAYER_HEAD).setName(MessageUtil.ofText(parent.getPlayer(), "previous_page")).setSkullOwner(GuiUtil.PREVIOUS_PAGE_ICON).asStack(),
((index, type, action) -> {
this.page -= 1;
if (this.page < 0) {
Expand All @@ -64,7 +64,7 @@ private void updateNavigation() {
);

navigationLayer.setSlot(
5, new GuiElementBuilder().setItem(Items.PLAYER_HEAD).setName(MessageUtil.ofVomponent(parent.getPlayer(), "next_page")).setSkullOwner(GuiUtil.NEXT_PAGE_ICON).asStack(),
5, new GuiElementBuilder().setItem(Items.PLAYER_HEAD).setName(MessageUtil.ofText(parent.getPlayer(), "next_page")).setSkullOwner(GuiUtil.NEXT_PAGE_ICON).asStack(),
((index, type, action) -> {
this.page += 1;
if (this.page >= getMaxPage()) {
Expand All @@ -75,7 +75,7 @@ private void updateNavigation() {
);
navigationLayer.setSlot(4, new GuiElementBuilder(Items.PLAYER_HEAD)
.setSkullOwner(GuiUtil.QUESTION_MARK_ICON)
.setName(MessageUtil.ofVomponent(parent.getPlayer(), "head.page", this.page + 1, this.getMaxPage()))
.setName(MessageUtil.ofText(parent.getPlayer(), "head.page", this.page + 1, this.getMaxPage()))
);
}

Expand All @@ -86,7 +86,7 @@ private void updateContent() {
var builder = GuiElementBuilder.from(head.of());
if (HeadInitializer.headHandler.model().economyType != HeadInitializer.EconomyType.FREE) {
builder.addLoreLine(Text.empty());
builder.addLoreLine(MessageUtil.ofVomponent(parent.getPlayer(), "head.price").copy().append(module.getCost()));
builder.addLoreLine(MessageUtil.ofText(parent.getPlayer(), "head.price").copy().append(module.getCost()));
}

contentLayer.setSlot(i, builder.asStack(), (index, type, action) -> processHeadClick(head, type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PlayerInputGui(HeadGui parentGui) {
this.setDefaultInputValue("");
this.setSlot(1, Items.PLAYER_HEAD.getDefaultStack());
this.resetSearchResult();
this.setTitle(MessageUtil.ofVomponent(player, "head.category.player"));
this.setTitle(MessageUtil.ofText(player, "head.category.player"));
}

private void resetSearchResult() {
Expand Down Expand Up @@ -74,7 +74,7 @@ public void onTick() {
GuiElementBuilder builder = new GuiElementBuilder().setItem(Items.PLAYER_HEAD);
if (HeadInitializer.headHandler.model().economyType != HeadInitializer.EconomyType.FREE) {
builder.addLoreLine(Text.empty());
builder.addLoreLine(MessageUtil.ofVomponent(player, "head.price").copy().append(module.getCost()));
builder.addLoreLine(MessageUtil.ofText(player, "head.price").copy().append(module.getCost()));
}

builder.setSkullOwner(profile, Fuji.SERVER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public SearchInputGui(HeadGui parentGui) {

this.setDefaultInputValue("");
this.setSlot(1, Items.BARRIER.getDefaultStack());
this.setSlot(2, new GuiElementBuilder().setItem(Items.SLIME_BALL).setName(MessageUtil.ofVomponent(player, "confirm")).setCallback((index, type, action, gui) -> {
this.setSlot(2, new GuiElementBuilder().setItem(Items.SLIME_BALL).setName(MessageUtil.ofText(player, "confirm")).setCallback((index, type, action, gui) -> {

String search = this.getInput();
var heads = module.heads.values().stream()
.filter(head -> head.name.toLowerCase().contains(search.toLowerCase()) || head.getTagsOrEmpty().toLowerCase().contains(search.toLowerCase()))
.collect(Collectors.toList());
var $gui = new PagedHeadsGui(this, heads);
$gui.setTitle(MessageUtil.ofVomponent(player, "head.search.output", search));
$gui.setTitle(MessageUtil.ofText(player, "head.search.output", search));
$gui.open();
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Optional<ServerMetadata.Favicon> getRandomIcon() {
}

public Text getRandomDescription() {
return MessageUtil.ofVomponent(motd.get(new Random().nextInt(motd.size())));
return MessageUtil.ofText(motd.get(new Random().nextInt(motd.size())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ public void onClose() {
/* input type */
SimpleGui selectWorkTypeGui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
selectWorkTypeGui.setLockPlayerInventory(true);
selectWorkTypeGui.setTitle(MessageUtil.ofVomponent(player, "works.work.add.select_work_type.title"));
selectWorkTypeGui.setTitle(MessageUtil.ofText(player, "works.work.add.select_work_type.title"));
for (int i = 0; i < 27; i++) {
selectWorkTypeGui.setSlot(i, new GuiElementBuilder().setItem(Items.PINK_STAINED_GLASS_PANE));
}
selectWorkTypeGui.setSlot(11, new GuiElementBuilder().setItem(Items.GUNPOWDER).setName(MessageUtil.ofVomponent(player, "works.non_production_work.name")).setCallback(() -> {
selectWorkTypeGui.setSlot(11, new GuiElementBuilder().setItem(Items.GUNPOWDER).setName(MessageUtil.ofText(player, "works.non_production_work.name")).setCallback(() -> {
// add
worksHandler.model().works.add(0, new NonProductionWork(player, name));
MessageUtil.sendActionBar(player, "works.work.add.done");
MessageUtil.sendBroadcast("works.work.add.broadcast", player.getGameProfile().getName(), name);
selectWorkTypeGui.close();
}));
selectWorkTypeGui.setSlot(15, new GuiElementBuilder().setItem(Items.REDSTONE).setName(MessageUtil.ofVomponent(player, "works.production_work.name")).setCallback(() -> {
selectWorkTypeGui.setSlot(15, new GuiElementBuilder().setItem(Items.REDSTONE).setName(MessageUtil.ofText(player, "works.production_work.name")).setCallback(() -> {
// add
ProductionWork work = new ProductionWork(player, name);
worksHandler.model().works.add(0, work);
Expand Down Expand Up @@ -127,7 +127,7 @@ private boolean hasPermission(ServerPlayerEntity player, Work work) {

final SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false);
gui.setLockPlayerInventory(true);
gui.setTitle(MessageUtil.ofVomponent(player, "works.list.title", page + 1));
gui.setTitle(MessageUtil.ofText(player, "works.list.title", page + 1));

/* draw content */
for (int slotIndex = 0; slotIndex < PAGE_SIZE; slotIndex++) {
Expand All @@ -136,7 +136,7 @@ private boolean hasPermission(ServerPlayerEntity player, Work work) {
Work work = source.get(workIndex);
gui.setSlot(slotIndex, new GuiElementBuilder()
.setItem(work.asItem())
.setName(MessageUtil.ofVomponent(work.name))
.setName(MessageUtil.ofText(work.name))
.setLore(work.asLore(player))
.setCallback((index, clickType, actionType) -> {
/* left click -> visit */
Expand Down Expand Up @@ -178,46 +178,46 @@ private boolean hasPermission(ServerPlayerEntity player, Work work) {
List<Work> finalSource = source;
gui.setSlot(45, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "previous_page"))
.setName(MessageUtil.ofText(player, "previous_page"))
.setSkullOwner(GuiUtil.PREVIOUS_PAGE_ICON)
.setCallback(() -> {
if (page == 0) return;
$listWorks(player, finalSource, page - 1);
}));
gui.setSlot(48, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "works.list.add"))
.setName(MessageUtil.ofText(player, "works.list.add"))
.setSkullOwner(GuiUtil.PLUS_ICON)
.setCallback(() -> $addWork(player))
);
if (source == worksHandler.model().works) {
gui.setSlot(49, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "works.list.my_works"))
.setName(MessageUtil.ofText(player, "works.list.my_works"))
.setSkullOwner(GuiUtil.HEART_ICON)
.setCallback(() -> $myWorks(player))
);
} else {
gui.setSlot(49, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "works.list.all_works"))
.setName(MessageUtil.ofText(player, "works.list.all_works"))
.setSkullOwner(GuiUtil.A_ICON)
.setCallback(() -> $listWorks(player, null, 0))
);
}
gui.setSlot(50, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "works.list.help"))
.setName(MessageUtil.ofText(player, "works.list.help"))
.setSkullOwner(GuiUtil.QUESTION_MARK_ICON)
.setLore(MessageUtil.ofVomponents(player, "works.list.help.lore")));
gui.setSlot(52, new GuiElementBuilder()
.setItem(Items.COMPASS)
.setName(MessageUtil.ofVomponent(player, "search"))
.setName(MessageUtil.ofText(player, "search"))
.setCallback(() -> $searchWorks(player, finalSource))
);
gui.setSlot(53, new GuiElementBuilder()
.setItem(Items.PLAYER_HEAD)
.setName(MessageUtil.ofVomponent(player, "next_page"))
.setName(MessageUtil.ofText(player, "next_page"))
.setSkullOwner(GuiUtil.NEXT_PAGE_ICON)
.setCallback(() -> {
if ((page + 1) * PAGE_SIZE >= finalSource.size()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public InputSignGui(ServerPlayerEntity player, String promptKey) {
this.setSignType(Blocks.CHERRY_WALL_SIGN);
this.setColor(DyeColor.BLACK);
if (promptKey != null) {
this.setLine(3, MessageUtil.ofVomponent(promptKey));
this.setLine(3, MessageUtil.ofText(promptKey));
}
this.setAutoUpdate(false);
}
Expand Down
Loading

0 comments on commit ab820a6

Please sign in to comment.