Expand CustomClickEvent to have raw and parsed data

This commit is contained in:
md_5 2025-05-22 22:16:22 +10:00
parent f1f5be18f9
commit f8de305477
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 23 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import lombok.ToString;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Cancellable;
import net.md_5.bungee.api.plugin.Event;
import org.jetbrains.annotations.ApiStatus;
/**
* Called after a {@link ProxiedPlayer} runs a custom action from a chat event
@ -15,6 +16,7 @@ import net.md_5.bungee.api.plugin.Event;
@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
@ApiStatus.Experimental
public class CustomClickEvent extends Event implements Cancellable
{
@ -32,11 +34,19 @@ public class CustomClickEvent extends Event implements Cancellable
*/
private final String id;
/**
* Form data, may be null. If a form submission, usually contains a
* The raw data as submitted.
*/
private final String rawData;
/**
* The parsed form data.
* <br>
* If a form submission, usually contains a
* {@code CustomClickEvent.ACTION_KEY} key with the ID of the relevant
* submission action.
* <br>
* If not a form submission, then may be null.
*/
private final Map<String, String> data;
private final Map<String, String> parsedData;
/**
* Cancelled state.
*/

View File

@ -394,12 +394,20 @@ public class UpstreamBridge extends PacketHandler
for ( String line : lines )
{
String[] split = line.split( "\t", 2 );
parsed.put( split[0], ( split.length > 1 ) ? split[1] : "" );
if ( split.length > 1 )
{
parsed.put( split[0], split[1] );
}
}
data = parsed.buildOrThrow();
if ( data.isEmpty() )
{
data = null;
}
data = parsed.build();
}
CustomClickEvent event = new CustomClickEvent( con, customClickAction.getId(), data );
CustomClickEvent event = new CustomClickEvent( con, customClickAction.getId(), customClickAction.getData(), data );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
{
throw CancelSendSignal.INSTANCE;