WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code
MIT License
474 stars 113 forks source link

Receive text while the player is typing #172

Closed XMichaelLP closed 3 years ago

XMichaelLP commented 3 years ago

Is it possible that if the player enters something in the AnvilGUI, that the text will be sent without pressing the item beforehand. So that you know what I mean, similar to the TabCompleteEvent only with an anvil. Could you develop something like that?

WesJD commented 3 years ago

While this is a cool idea, it would make the library require either a dependency on ProtocolLib, or the inclusion of PacketEvents. Those are both pretty large dependencies for this library, and I believe that you could pretty easily achieve what you're looking for by listening to the events yourself with one of those dependencies.

For example, you'd create an incoming packet listener for PacketPlayInItemName. Have an AnvilGUiHelper class in your project which opens AnvilGUIs, and once opened, stores the object reference in a Map<Player, AnvilGUI>. In your packet listener, you can now check if the player has an AnvilGUI open, and modify the incoming text accordingly, or call a method on the AnvilGUI object.