Skip to content

Commit

Permalink
reorganize chat event
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Jun 3, 2022
1 parent 5f165e3 commit 38a52fc
Showing 1 changed file with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,74 @@
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.entity.living.player.PlayerChatFormatter;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;

import java.util.Optional;

/**
* Fired when the {@link Component} being sent to a {@link PlayerChatFormatter} was
* due to chatting.
* Fired when sending a chat message.
* To modify the message use {@link PlayerChatEvent.Decorate}.
*/
public interface PlayerChatEvent extends AudienceMessageEvent, Cancellable {
@GenerateFactoryMethod
public interface PlayerChatEvent extends Event, Cancellable {

/**
* Gets the original formatter that this message will be sent through.
* Gets the message.
*
* @return The original formatter used
* @return Message
*/
PlayerChatFormatter originalChatFormatter();
Component message();

/**
* Gets the current formatter that this message will be sent through.
*
* @return The formatter the message in this event will be sent through
* Fired for each player receiving a message.
*/
Optional<PlayerChatFormatter> chatFormatter();
interface Receive extends AudienceMessageEvent, Cancellable {

/**
* Sets the formatter for this message to go trough.
* <p>If the target audience is a {@link net.kyori.adventure.audience.ForwardingAudience}
* the {@link PlayerChatFormatter} will be applied to each of its {@link ForwardingAudience#audiences()}</p>
*
* @param router The router to set
*/
void setChatFormatter(@Nullable PlayerChatFormatter router);
/**
* Gets the original formatter that this message will be sent through.
*
* @return The original formatter used
*/
PlayerChatFormatter originalChatFormatter();

/**
* Gets the original chat message.
*
* <p>This message is the original chat message, without any formatting
* whatsoever.</p>
*
* <p>In Vanilla, this is equivalent to what a player typed into the
* chat box (no name prefix or other elements).</p>
*
* @return The original chat message
*/
@Override
Component originalMessage();
/**
* Gets the current formatter that this message will be sent through.
*
* @return The formatter the message in this event will be sent through
*/
Optional<PlayerChatFormatter> chatFormatter();

/**
* Gets the chat message.
*
* @return The chat message
*/
@Override
Component message();
/**
* Sets the formatter for this message to go through.
* <p>If the target audience is a {@link net.kyori.adventure.audience.ForwardingAudience}
* the {@link PlayerChatFormatter} will be applied to each of its {@link ForwardingAudience#audiences()}</p>
*
* @param router The router to set
*/
void setChatFormatter(@Nullable PlayerChatFormatter router);

This comment has been minimized.

Copy link
@Zidane

Zidane Jun 4, 2022

Member

Should this possibly take a function where the input is the Audience and the output is the formatted message?

This comment has been minimized.

Copy link
@Zidane

Zidane Jun 4, 2022

Member

I should read the formatter...ignore this comment.


}

/**
* Sets the chat message.
*
* @param message The chat message
* Fired when decorating a message sent by a player or via {@link ServerPlayer#simulateChat} or creating the preview for a chat message.
*/
@Override
void setMessage(final Component message);
interface Decorate extends MessageEvent {

/**
* Gets the original chat message.
*
* <p>In Vanilla, this is equivalent to what a player typed into the
* chat box (no name prefix or other elements).</p>
*
* @return The original chat message
*/
@Override
Component originalMessage();

}


}

0 comments on commit 38a52fc

Please sign in to comment.