Search in sources :

Example 1 with MessageType

use of net.minecraft.network.MessageType 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)

Aggregations

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