40 lines
1.7 KiB
Java
40 lines
1.7 KiB
Java
package wtf.hak.survivalfabric.mixin;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.text.Text;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
|
import wtf.hak.survivalfabric.config.ConfigManager;
|
|
|
|
@Mixin(ServerPlayerEntity.class)
|
|
public class ServerPlayerEntityMixin {
|
|
|
|
/**
|
|
* Change player list name if enabled
|
|
*/
|
|
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
|
|
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
|
|
if (ConfigManager.getConfig().dimensionIndicatorEnabled) {
|
|
ServerPlayerEntity p = (ServerPlayerEntity) (Object) this;
|
|
String world = p.getServerWorld().getRegistryKey().getValue().toTranslationKey();
|
|
String finalName;
|
|
if (!SpectatorCommand.spectating.containsKey(p)) {
|
|
finalName = switch (world) {
|
|
case "minecraft.overworld" -> ConfigManager.getConfig().overworldPrefix;
|
|
case "minecraft.the_nether" -> ConfigManager.getConfig().netherPrefix;
|
|
case "minecraft.the_end" -> ConfigManager.getConfig().endPrefix;
|
|
default -> ConfigManager.getConfig().unknownPrefix;
|
|
};
|
|
} else
|
|
finalName = ConfigManager.getConfig().spectatorPrefix;
|
|
|
|
finalName += "§7" + p.getName().getString();
|
|
|
|
cir.setReturnValue(Text.of(finalName));
|
|
}
|
|
}
|
|
}
|