Skip to content

Commit

Permalink
feature: Afk module supports placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Jul 15, 2024
1 parent d641136 commit 7ef57c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public class Tpa {
}

@Documentation("""
This module provides `/work` command.
This module provides `/works` command.
A `work` means a project (a building, a red-stone device ...) that crafted by a player.
Expand Down Expand Up @@ -787,7 +787,7 @@ public class Afk {

public boolean enable = false;
@Documentation("The tab-name format when a player is afk")
public String format = "<gray>[AFK] <reset>%player_display_name%";
public String format = "<gray>[AFK] <reset>%player:name_visual%";

@Documentation("The afk checker is a timer to check and mark the player's recently active time.")
public AfkChecker afk_checker = new AfkChecker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.sakurawald.config.Configs;
import io.github.sakurawald.module.initializer.afk.AfkStateAccessor;
import io.github.sakurawald.util.MessageUtil;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.Component;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -18,8 +18,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

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

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerMixin implements AfkStateAccessor {
Expand All @@ -43,9 +42,7 @@ public abstract class ServerPlayerMixin implements AfkStateAccessor {

if (accessor.fuji$isAfk()) {
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(toText(component));
cir.setReturnValue(ofText(player, false, Configs.configHandler.model().modules.afk.format));
} else {
cir.setReturnValue(null);
}
Expand Down

0 comments on commit 7ef57c1

Please sign in to comment.