Update to 1.19-pre1

This commit is contained in:
shedaniel
2022-05-19 20:19:08 +08:00
parent 0adf9a2e6d
commit 258d23c62e
12 changed files with 172 additions and 91 deletions

View File

@@ -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);
}
}
}