Skip to content

Commit

Permalink
Add botPlayerListPrefix rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alikindsys committed Jan 4, 2024
1 parent 9208c87 commit 7c79f68
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/blocovermelho/bvextension/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public class Settings {
categories = {SURVIVAL, EXPERIMENTAL, "bv-extension"}
)
public static boolean botsDontSleep = false;

@Rule(
categories = {SURVIVAL, "PROTOCOL", "bv-extension" }
)
public static boolean botPlayerListPrefix = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.blocovermelho.bvextension.mixin;

import carpet.CarpetServer;
import carpet.patches.EntityPlayerMPFake;
import com.mojang.authlib.GameProfile;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.minecraft.network.encryption.PublicPlayerSession;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import org.blocovermelho.bvextension.Extension;
import org.blocovermelho.bvextension.Settings;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.UUID;

@Mixin(PlayerListS2CPacket.Entry.class)
public abstract class BotPrefixPlayerList {
@Shadow @Final private GameProfile profile;

@Mutable
@Shadow
@Final
@Nullable
private Text displayName;

@Inject(
method = "<init>(Ljava/util/UUID;Lcom/mojang/authlib/GameProfile;ZILnet/minecraft/world/GameMode;Lnet/minecraft/text/Text;Lnet/minecraft/network/encryption/PublicPlayerSession$Serialized;)V",
at = @At(value = "RETURN")
)
public void bvext$botPrefix(UUID uuid, GameProfile profile, boolean listed, int ping, GameMode gameMode, Text text, PublicPlayerSession.Serialized chatSession, CallbackInfo ci) {
if (!Settings.botPlayerListPrefix) { return; }
var player = CarpetServer.minecraft_server.getPlayerManager().getPlayer(this.profile.getId());
if (player instanceof EntityPlayerMPFake) {
var botName = Component.text("[ʙᴏᴛ]").color(TextColor.color(0x9a26ff))
.appendSpace()
.append(
Component.text(player.getDisplayName().getString())
.color(TextColor.color(0xf0d3e0))
);

this.displayName = Extension.audiences.toNative(botName);
}
}

}
3 changes: 2 additions & 1 deletion src/main/resources/assets/bv-extension/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"carpet.rule.carefulBreak.desc": "Places the mined block in the player inventory when sneaking",
"carpet.rule.botsDontSleep.desc" : "Makes carpet bots don't count towards playersSleepingPercentage"
"carpet.rule.botsDontSleep.desc" : "Makes carpet bots don't count towards playersSleepingPercentage",
"carpet.rule.botPlayerListPrefix.desc": "Adds a prefix to bots on the player list"
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/bv-extension/lang/pt_br.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"carpet.rule.carefulBreak.desc": "Coloca o bloco minerado direto no inventário quando o jogador está agachado",
"carpet.rule.botsDontSleep.desc" : "Faz com que bots do carpet não contem para a gamerule playersSleepingPercentage"
"carpet.rule.botsDontSleep.desc" : "Faz com que bots do carpet não contem para a gamerule playersSleepingPercentage",
"carpet.rule.botPlayerListPrefix.desc": "Adiciona um prefixo aos bots na lista de jogadores"
}
3 changes: 2 additions & 1 deletion src/main/resources/bv-extension.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"carefulBreak.TallBlockMixin",
"carefulBreak.PistonHeadMixin",
"carefulBreak.BedMixin",
"BotsDontSleep"
"BotsDontSleep",
"BotPrefixPlayerList"
],
"client": [
],
Expand Down

0 comments on commit 7c79f68

Please sign in to comment.