[FEAT] MessageBroadcastEvent
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageBroadcastEvent extends CraterEvent {
|
||||
|
||||
private final Component component;
|
||||
private final Function<ServerPlayer, Component> function;
|
||||
private final boolean bl;
|
||||
|
||||
public MessageBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl) {
|
||||
this.component = component;
|
||||
this.function = function;
|
||||
this.bl = bl;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public boolean isBl() {
|
||||
return bl;
|
||||
}
|
||||
|
||||
public Function<ServerPlayer, Component> getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCancel() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterPlayerEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.MessageBroadcastEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -15,10 +16,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public class PlayerListMixin {
|
||||
|
||||
@Inject(method = "broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Z)V", at = @At("HEAD"))
|
||||
private void injectBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, CallbackInfo ci) {
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(component, function, bl);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
|
||||
private void injectPlayerLoginEvent(Connection connection, ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
CraterPlayerEvent.PlayerLoggedIn loggedIn = new CraterPlayerEvent.PlayerLoggedIn(serverPlayer);
|
||||
|
Reference in New Issue
Block a user