-
Notifications
You must be signed in to change notification settings - Fork 0
/
AHServerEventFactory.java
37 lines (31 loc) · 1.6 KB
/
AHServerEventFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.auioc.mcmod.arnicalib.server.event;
import static org.auioc.mcmod.arnicalib.ArnicaLib.LOGGER;
import org.apache.logging.log4j.Marker;
import org.auioc.mcmod.arnicalib.base.log.LogUtil;
import org.auioc.mcmod.arnicalib.game.chat.TextUtils;
import org.auioc.mcmod.arnicalib.server.event.impl.ServerLoginEvent;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
public final class AHServerEventFactory {
private static final Marker MARKER = LogUtil.getMarker("ServerHooks");
private static final IEventBus BUS = MinecraftForge.EVENT_BUS;
// Return true if the event was Cancelable cancelled
public static boolean onServerLogin(final ClientIntentionPacket packet, final Connection manager) {
ServerLoginEvent event = new ServerLoginEvent(packet, manager);
boolean cancelled = BUS.post(event);
if (cancelled) {
var message = TextUtils.literal(event.getMessage());
manager.send(new ClientboundLoginDisconnectPacket(message));
manager.disconnect(message);
LOGGER.info(
LogUtil.getMarker("ServerLogin").addParents(MARKER),
String.format("Disconnecting %s connection attempt from %s: %s", event.getPacket().getIntention(), event.getNetworkManager().getRemoteAddress(), event.getMessage())
);
return true;
}
return false;
}
}