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);
}
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;
}
Aggregations