Search in sources :

Example 1 with BadgeInstance

use of com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance in project KahzerxMod by otakucraft.

the class PlayerManagerMixin method onBroadcast.

@Redirect(method = "broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;sendMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V"))
private void onBroadcast(ServerPlayerEntity instance, Text message, MessageType type, UUID sender) {
    ServerPlayerEntity player = server.getPlayerManager().getPlayer(sender);
    if (BadgeExtension.isExtensionEnabled && player != null) {
        MutableText t = new LiteralText(String.format("Name: %s", player.getName().getString()));
        if (!BadgeExtension.playerBadges.get(sender.toString()).isEmpty()) {
            t.append(new LiteralText("\nBadges:"));
        }
        for (BadgeInstance badgeInstance : BadgeExtension.playerBadges.get(sender.toString())) {
            t.append(new LiteralText("\n" + badgeInstance.getBadge()).styled(style -> style.withColor(Formatting.byColorIndex(badgeInstance.getColorIndex()))));
            t.append(new LiteralText(String.format(": %s", badgeInstance.getDescription())).styled(style -> style.withColor(Formatting.WHITE)));
        }
        ((LiteralText) ((TranslatableText) message).getArgs()[0]).styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, t)));
    }
    instance.sendMessage(message, type, sender);
}
Also used : Redirect(org.spongepowered.asm.mixin.injection.Redirect) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) MessageType(net.minecraft.network.MessageType) PlayerManager(net.minecraft.server.PlayerManager) BadgeExtension(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeExtension) UUID(java.util.UUID) net.minecraft.text(net.minecraft.text) Final(org.spongepowered.asm.mixin.Final) MinecraftServer(net.minecraft.server.MinecraftServer) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) At(org.spongepowered.asm.mixin.injection.At) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with BadgeInstance

use of com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance in project KahzerxMod by otakucraft.

the class ServerPlayNetworkHandlerMixin method onGetDisplayName.

@Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getDisplayName()Lnet/minecraft/text/Text;"))
private Text onGetDisplayName(ServerPlayerEntity instance) {
    MutableText name = (MutableText) instance.getDisplayName();
    if (BadgeExtension.isExtensionEnabled) {
        List<BadgeInstance> badges = BadgeExtension.playerBadges.get(instance.getUuidAsString());
        if (badges.size() != 0) {
            name.append(new LiteralText(" "));
        }
        for (int i = badges.size() - 1; i >= 0; i--) {
            int finalI = i;
            name.append(new LiteralText(badges.get(i).getBadge()).styled(style -> style.withColor(Formatting.byColorIndex(badges.get(finalI).getColorIndex()))));
            if (i < badges.size() - 2) {
                break;
            }
        }
    }
    return name;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Mixin(org.spongepowered.asm.mixin.Mixin) Redirect(org.spongepowered.asm.mixin.injection.Redirect) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) MutableText(net.minecraft.text.MutableText) BadgeExtension(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeExtension) Text(net.minecraft.text.Text) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) At(org.spongepowered.asm.mixin.injection.At) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) LiteralText(net.minecraft.text.LiteralText) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

BadgeExtension (com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeExtension)2 BadgeInstance (com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 Formatting (net.minecraft.util.Formatting)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 At (org.spongepowered.asm.mixin.injection.At)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 List (java.util.List)1 UUID (java.util.UUID)1 MessageType (net.minecraft.network.MessageType)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 PlayerManager (net.minecraft.server.PlayerManager)1 ServerPlayNetworkHandler (net.minecraft.server.network.ServerPlayNetworkHandler)1 net.minecraft.text (net.minecraft.text)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1 Text (net.minecraft.text.Text)1 Final (org.spongepowered.asm.mixin.Final)1 Shadow (org.spongepowered.asm.mixin.Shadow)1