ConnectionEstablishedEvent

This commit is contained in:
LOOHP 2023-01-10 15:27:15 +00:00
parent 9f2c426a50
commit ba0f98b6c7
3 changed files with 215 additions and 175 deletions

View File

@ -0,0 +1,37 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2023. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2023. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.events.connection;
import com.loohp.limbo.events.Event;
import com.loohp.limbo.network.ClientConnection;
public class ConnectionEstablishedEvent extends Event {
private ClientConnection connection;
public ConnectionEstablishedEvent(ClientConnection connection) {
this.connection = connection;
}
public ClientConnection getConnection() {
return connection;
}
}

View File

@ -22,15 +22,15 @@ package com.loohp.limbo.events.player;
import com.loohp.limbo.events.Cancellable;
import com.loohp.limbo.events.Event;
import com.loohp.limbo.network.ClientConnection;
import net.md_5.bungee.api.chat.BaseComponent;
import net.kyori.adventure.text.Component;
public class PlayerLoginEvent extends Event implements Cancellable {
private ClientConnection connection;
private final ClientConnection connection;
private boolean cancelled;
private BaseComponent[] cancelReason;
private Component cancelReason;
public PlayerLoginEvent(ClientConnection connection, boolean cancelled, BaseComponent... cancelReason) {
public PlayerLoginEvent(ClientConnection connection, boolean cancelled, Component cancelReason) {
this.connection = connection;
this.cancelled = cancelled;
this.cancelReason = cancelReason;
@ -40,11 +40,11 @@ public class PlayerLoginEvent extends Event implements Cancellable {
return connection;
}
public BaseComponent[] getCancelReason() {
public Component getCancelReason() {
return cancelReason;
}
public void setCancelReason(BaseComponent... cancelReason) {
public void setCancelReason(Component cancelReason) {
this.cancelReason = cancelReason;
}

View File

@ -21,6 +21,7 @@ package com.loohp.limbo.network;
import com.loohp.limbo.Limbo;
import com.loohp.limbo.entity.EntityEquipment;
import com.loohp.limbo.events.connection.ConnectionEstablishedEvent;
import com.loohp.limbo.events.inventory.AnvilRenameInputEvent;
import com.loohp.limbo.events.inventory.InventoryCloseEvent;
import com.loohp.limbo.events.inventory.InventoryCreativeEvent;
@ -352,6 +353,8 @@ public class ClientConnection extends Thread {
state = ClientState.DISCONNECTED;
}
Limbo.getInstance().getEventsManager().callEvent(new ConnectionEstablishedEvent(this));
PacketHandshakingIn handshake = (PacketHandshakingIn) channel.readPacket(handShakeSize);
boolean isBungeecord = Limbo.getInstance().getServerProperties().isBungeecord();
@ -546,7 +549,7 @@ public class ClientConnection extends Thread {
}
}
PlayerLoginEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false));
PlayerLoginEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerLoginEvent(this, false, Component.empty()));
if (event.isCancelled()) {
disconnectDuringLogin(event.getCancelReason());
}