Added customizable config messages & feature toggles

This commit is contained in:
2025-03-25 22:59:05 +01:00
parent 8377f36114
commit c8f907dc57
8 changed files with 124 additions and 50 deletions

View File

@ -7,28 +7,30 @@ 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.utils.Messages;
import wtf.hak.survivalfabric.config.ConfigManager;
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin {
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
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" -> Messages.OVERWORLD_PREFIX;
case "minecraft.the_nether" -> Messages.NETHER_PREFIX;
case "minecraft.the_end" -> Messages.END_PREFIX;
default -> Messages.UNKNOWN_PREFIX;
};
} else
finalName = Messages.SPECTATOR_PREFIX;
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();
finalName += "§7" + p.getName().getString();
cir.setReturnValue(Text.of(finalName));
cir.setReturnValue(Text.of(finalName));
}
}
}