Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.quiltservertools.ledger.mixin;

import com.github.quiltservertools.ledger.commands.subcommands.PageCommand;
import com.github.quiltservertools.ledger.utility.MessageUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.network.protocol.common.ServerboundCustomClickActionPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
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.CallbackInfo;

@Mixin(ServerCommonPacketListenerImpl.class)
public class ServerCommonPacketListenerImplMixin {
@Inject(method = "handleCustomClickAction", at = @At("HEAD"), cancellable = true)
private void handleLedgerPageChangeClick(ServerboundCustomClickActionPacket packet, CallbackInfo ci) {
if (!packet.id().equals(MessageUtils.INSTANCE.getPageChangeAction())) return;
if (!((Object) this instanceof ServerGamePacketListenerImpl game)) return;
ServerPlayer player = game.player;
packet.payload().flatMap(Tag::asCompound)
.flatMap(root -> root.getInt("page"))
.ifPresent(page ->
PageCommand.INSTANCE.page(player.createCommandSourceStack(), page)
);
ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.github.quiltservertools.ledger.commands.subcommands
import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.commands.BuildableCommand
import com.github.quiltservertools.ledger.database.DatabaseManager
import com.github.quiltservertools.ledger.utility.Context
import com.github.quiltservertools.ledger.utility.LiteralNode
import com.github.quiltservertools.ledger.utility.MessageUtils
import com.github.quiltservertools.ledger.utility.TextColorPallet
import com.mojang.brigadier.arguments.IntegerArgumentType
import kotlinx.coroutines.launch
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.Commands.argument
import net.minecraft.commands.Commands.literal
import net.minecraft.network.chat.Component
Expand All @@ -18,13 +18,11 @@ object PageCommand : BuildableCommand {
literal("page")
.then(
argument("page", IntegerArgumentType.integer(1))
.executes { page(it, IntegerArgumentType.getInteger(it, "page")) }
.executes { page(it.source, IntegerArgumentType.getInteger(it, "page")) }
)
.build()

private fun page(context: Context, page: Int): Int {
val source = context.source

fun page(source: CommandSourceStack, page: Int): Int {
val params = Ledger.searchCache[source.textName]
if (params != null) {
Ledger.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ import com.github.quiltservertools.ledger.network.Networking.hasNetworking
import com.github.quiltservertools.ledger.network.packet.action.ActionS2CPacket
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
import net.minecraft.commands.CommandSourceStack
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.ClickEvent
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.HoverEvent
import net.minecraft.network.chat.MutableComponent
import net.minecraft.network.chat.Style
import net.minecraft.resources.Identifier
import java.time.Duration
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.*
import kotlin.time.ExperimentalTime
import kotlin.time.toKotlinDuration

object MessageUtils {
val pageChangeAction: Identifier = Ledger.identifier("page-change")

@OptIn(ExperimentalTime::class)
suspend fun sendSearchResults(source: CommandSourceStack, results: SearchResults, header: Component) {
// If the player has a Ledger compatible client, we send results as action packets rather than as chat messages
Expand All @@ -46,13 +51,15 @@ object MessageUtils {
Component.translatable(
"text.ledger.footer.page_backward"
).setStyle(TextColorPallet.primaryVariant).withStyle {
val tag: CompoundTag = CompoundTag().apply { this.putInt("page", results.page-1) }

if (results.page > 1) {
it.withHoverEvent(
HoverEvent.ShowText(
Component.translatable("text.ledger.footer.page_backward.hover")
)
).withClickEvent(
ClickEvent.RunCommand("/lg pg ${results.page - 1}")
ClickEvent.Custom(pageChangeAction, Optional.of(tag))
)
} else {
Style.EMPTY
Expand All @@ -63,13 +70,15 @@ object MessageUtils {
Component.translatable(
"text.ledger.footer.page_forward"
).setStyle(TextColorPallet.primaryVariant).withStyle {
val tag: CompoundTag = CompoundTag().apply { this.putInt("page", results.page+1) }

if (results.page < results.pages) {
it.withHoverEvent(
HoverEvent.ShowText(
Component.translatable("text.ledger.footer.page_forward.hover")
)
).withClickEvent(
ClickEvent.RunCommand("/lg pg ${results.page + 1}")
ClickEvent.Custom(pageChangeAction, Optional.of(tag))
)
} else {
Style.EMPTY
Expand Down
36 changes: 18 additions & 18 deletions src/main/resources/ledger.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
"required": true,
"package": "com.github.quiltservertools.ledger.mixin",
"mixins": [
"BlockBehaviourMixin",
"AbstractContainerMenuMixin",
"AnvilMenuMixin",
"AxeItemMixin",
"BaseContainerBlockEntityMixin",
"BlockBehaviourMixin",
"BlockItemMixin",
"BlockMixin",
"BucketDispenserBehaviorMixin",
"BucketItemMixin",
"CampfireBlockEntityMixin",
"ChestBlockMixin",
"CopperGolemGiveMixin",
"CompoundContainerMixin",
"ContainersMixin",
"CopperGolemGiveMixin",
"DyeItemMixin",
"ServerExplosionMixin",
"FillCommandMixin",
"FlintAndSteelItemMixin",
"FrostWalkerEnchantmentMixin",
"HoeItemMixin",
"HoneycombItemMixin",
"ContainersMixin",
"JukeboxPlayableMixin",
"WaterlilyBlockMixin",
"BaseContainerBlockEntityMixin",
"TransportItemsBetweenContainersMixin",
"PortalShapeMixin",
"AbstractContainerMenuMixin",
"ServerCommonPacketListenerImplMixin",
"ServerExplosionMixin",
"ServerPlayerMixin",
"SetBlockCommandMixin",
"ShovelItemMixin",
"SlotMixin",
"blocks.GrowingPlantBlockMixin",
"blocks.GrowingPlantHeadBlockMixin",
"TransportItemsBetweenContainersMixin",
"WaterlilyBlockMixin",
"blocks.BambooStalkBlockMixin",
"blocks.BedBlockMixin",
"blocks.ButtonBlockMixin",
Expand All @@ -52,13 +51,14 @@
"blocks.FenceGateBlockMixin",
"blocks.FireBlockMixin",
"blocks.FlowerPotBlockMixin",
"blocks.LiquidBlockMixin",
"blocks.GrowingPlantBlockMixin",
"blocks.GrowingPlantHeadBlockMixin",
"blocks.IceBlockMixin",
"blocks.JukeboxBlockMixin",
"blocks.LeavesBlockMixin",
"blocks.LeverBlockMixin",
"blocks.LiquidBlockMixin",
"blocks.NoteBlockMixin",
"blocks.WeatheringCopperGolemStatueBlockMixin",
"blocks.PointedDripstoneBlockMixin",
"blocks.RepeaterBlockMixin",
"blocks.RootedDirtBlockMixin",
Expand All @@ -68,27 +68,27 @@
"blocks.SpreadingSnowyDirtBlockMixin",
"blocks.SugarCaneBlockMixin",
"blocks.TrapDoorBlockMixin",
"blocks.WeatheringCopperGolemStatueBlockMixin",
"blocks.WetSpongeBlockMixin",
"blocks.cauldron.CauldronInteractionMixin",
"blocks.cauldron.CauldronBlockMixin",
"blocks.cauldron.CauldronInteractionMixin",
"blocks.cauldron.LayeredCauldronBlockMixin",
"blocks.coral.CoralPlantBlockMixin",
"blocks.coral.CoralPlantBlockMixin",
"blocks.coral.CoralFanBlockMixin",
"blocks.coral.CoralPlantBlockMixin",
"blocks.coral.CoralWallFanBlockMixin",
"blocks.lectern.AbstractContainerMenuMixin",
"blocks.lectern.LecternBlockMixin",
"blocks.lectern.LecternMenuMixin",
"blocks.lectern.AbstractContainerMenuMixin",
"blocks.sign.SignBlockMixin",
"blocks.sign.SignBlockEntityMixin",
"blocks.sign.SignBlockMixin",
"entities.AbstractHurtingProjectileMixin",
"entities.ArmorStandMixin",
"entities.CatMixin",
"entities.CopperGolemMixin",
"entities.CreeperMixin",
"entities.EndCrystalMixin",
"entities.EnderDragonMixin",
"entities.EvokerEntityWololoGoalMixin",
"entities.AbstractHurtingProjectileMixin",
"entities.FallingBlockEntityMixin",
"entities.ItemEntityMixin",
"entities.ItemFrameMixin",
Expand Down
Loading