mirror of
https://github.com/architectury/architectury-api.git
synced 2026-04-02 21:47:40 -05:00
Update to 1.19-pre1
This commit is contained in:
@@ -22,13 +22,16 @@ package dev.architectury.event.events.common;
|
||||
import dev.architectury.event.CompoundEventResult;
|
||||
import dev.architectury.event.Event;
|
||||
import dev.architectury.event.EventFactory;
|
||||
import dev.architectury.event.EventResult;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface ChatEvent {
|
||||
/**
|
||||
* @see Server#process(ServerPlayer, Component)
|
||||
* @see Server#process(ServerPlayer, ChatComponent)
|
||||
*/
|
||||
Event<Server> SERVER = EventFactory.createEventResult();
|
||||
|
||||
@@ -39,9 +42,37 @@ public interface ChatEvent {
|
||||
*
|
||||
* @param player The player who has sent the message, or null.
|
||||
* @param component The message as component.
|
||||
* @return A {@link CompoundEventResult} determining the outcome of the event,
|
||||
* if an outcome is set, the sent message is overridden.
|
||||
* @return A {@link EventResult} determining the outcome of the event,
|
||||
* the execution of the vanilla message may be cancelled by the result.
|
||||
*/
|
||||
CompoundEventResult<Component> process(@Nullable ServerPlayer player, Component component);
|
||||
EventResult process(@Nullable ServerPlayer player, ChatComponent component);
|
||||
}
|
||||
|
||||
interface ChatComponent {
|
||||
Component getRaw();
|
||||
|
||||
@Nullable
|
||||
Component getFiltered();
|
||||
|
||||
void setRaw(Component raw);
|
||||
|
||||
void setFiltered(@Nullable Component filtered);
|
||||
|
||||
default void modifyRaw(Function<Component, Component> function) {
|
||||
setRaw(function.apply(getRaw()));
|
||||
}
|
||||
|
||||
default void modifyFiltered(Function<Component, Component> function) {
|
||||
Component filtered = getFiltered();
|
||||
|
||||
if (filtered != null) {
|
||||
setFiltered(function.apply(filtered));
|
||||
}
|
||||
}
|
||||
|
||||
default void modifyBoth(Function<Component, Component> function) {
|
||||
modifyRaw(function);
|
||||
modifyFiltered(function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user