feat: Improved PreSendLoginEvent Result
This commit is contained in:
parent
1c7c50675a
commit
327b3394f1
@ -3,7 +3,6 @@ package me.adrianed.authmevelocity.api.velocity.event;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.velocitypowered.api.event.ResultedEvent;
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.event.ResultedEvent.GenericResult;
|
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
@ -13,12 +12,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* Event to be executed just before sending a player to another server after login/registration.
|
* Event to be executed just before sending a player to another server after login/registration.
|
||||||
* Here you have the ability to deny the event.
|
* Here you have the ability to deny the event.
|
||||||
*/
|
*/
|
||||||
public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
public final class PreSendOnLoginEvent implements ResultedEvent<ServerResult> {
|
||||||
|
|
||||||
private GenericResult result = GenericResult.allowed();
|
private ServerResult result;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final RegisteredServer actualserver;
|
private final RegisteredServer actualserver;
|
||||||
private final RegisteredServer serverToSend;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PreSendOnLoginEvent
|
* Create a new PreSendOnLoginEvent
|
||||||
@ -29,7 +27,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
public PreSendOnLoginEvent(@NotNull Player player, @NotNull RegisteredServer actualServer, @NotNull RegisteredServer serverToSend){
|
public PreSendOnLoginEvent(@NotNull Player player, @NotNull RegisteredServer actualServer, @NotNull RegisteredServer serverToSend){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.actualserver = actualServer;
|
this.actualserver = actualServer;
|
||||||
this.serverToSend = serverToSend;
|
result = ServerResult.allowed(serverToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,19 +46,11 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
return this.actualserver;
|
return this.actualserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtain the server to which the player will be sent
|
|
||||||
* @return the server to send the player
|
|
||||||
*/
|
|
||||||
public @NotNull RegisteredServer getSendServer(){
|
|
||||||
return this.serverToSend;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the result of the event
|
* Get the result of the event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public @NotNull GenericResult getResult() {
|
public @NotNull ServerResult getResult() {
|
||||||
return this.result;
|
return this.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +59,7 @@ public final class PreSendOnLoginEvent implements ResultedEvent<GenericResult> {
|
|||||||
* @param newresult the new result
|
* @param newresult the new result
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setResult(@NotNull GenericResult newresult) {
|
public void setResult(@NotNull ServerResult newResult) {
|
||||||
this.result = Objects.requireNonNull(newresult);
|
this.result = Objects.requireNonNull(newResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package me.adrianed.authmevelocity.api.velocity.event;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.ResultedEvent.Result;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
|
public record ServerResult(boolean result, RegisteredServer server) implements Result {
|
||||||
|
private static final ServerResult DENIED = new ServerResult(false, null);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ServerResult allowed(RegisteredServer server) {
|
||||||
|
return new ServerResult(true, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ServerResult denied() {
|
||||||
|
return DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user