Allow cancelling LoginEvents with component reasons.
Ultimately this PR was selected as it better matched the existing code in terms of using lombok and not adding incomplete interfacing. If for some reason a common interface is required, this can be implemented later. Thanks to yawkat also for the PR in #1336 -- it was difficult for the merger to compromise between this and #1957
This commit is contained in:
parent
2171ca9f51
commit
ea6680281f
@ -1,9 +1,13 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
|
||||
@ -23,7 +27,8 @@ public class LoginEvent extends AsyncEvent<LoginEvent> implements Cancellable
|
||||
/**
|
||||
* Message to use when kicking if this event is canceled.
|
||||
*/
|
||||
private String cancelReason;
|
||||
@Setter(AccessLevel.NONE)
|
||||
private BaseComponent[] cancelReasonComponents;
|
||||
/**
|
||||
* Connection attempting to login.
|
||||
*/
|
||||
@ -34,4 +39,31 @@ public class LoginEvent extends AsyncEvent<LoginEvent> implements Cancellable
|
||||
super( done );
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return reason to be displayed
|
||||
* @deprecated Use component methods instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getCancelReason()
|
||||
{
|
||||
return BaseComponent.toLegacyText( getCancelReasonComponents() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cancelReason reason to be displayed
|
||||
* @deprecated Use
|
||||
* {@link #setCancelReason(net.md_5.bungee.api.chat.BaseComponent...)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCancelReason(String cancelReason)
|
||||
{
|
||||
setCancelReason( TextComponent.fromLegacyText( cancelReason ) );
|
||||
}
|
||||
|
||||
public void setCancelReason(BaseComponent... cancelReason)
|
||||
{
|
||||
this.cancelReasonComponents = cancelReason;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
|
||||
@ -28,7 +32,8 @@ public class PreLoginEvent extends AsyncEvent<PreLoginEvent> implements Cancella
|
||||
/**
|
||||
* Message to use when kicking if this event is canceled.
|
||||
*/
|
||||
private String cancelReason;
|
||||
@Setter(AccessLevel.NONE)
|
||||
private BaseComponent[] cancelReasonComponents;
|
||||
/**
|
||||
* Connection attempting to login.
|
||||
*/
|
||||
@ -39,4 +44,31 @@ public class PreLoginEvent extends AsyncEvent<PreLoginEvent> implements Cancella
|
||||
super( done );
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return reason to be displayed
|
||||
* @deprecated Use component methods instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getCancelReason()
|
||||
{
|
||||
return BaseComponent.toLegacyText( getCancelReasonComponents() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cancelReason reason to be displayed
|
||||
* @deprecated Use
|
||||
* {@link #setCancelReason(net.md_5.bungee.api.chat.BaseComponent...)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCancelReason(String cancelReason)
|
||||
{
|
||||
setCancelReason( TextComponent.fromLegacyText( cancelReason ) );
|
||||
}
|
||||
|
||||
public void setCancelReason(BaseComponent... cancelReason)
|
||||
{
|
||||
this.cancelReasonComponents = cancelReason;
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( result.isCancelled() )
|
||||
{
|
||||
disconnect( result.getCancelReason() );
|
||||
disconnect( result.getCancelReasonComponents() );
|
||||
return;
|
||||
}
|
||||
if ( ch.isClosed() )
|
||||
@ -479,7 +479,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
if ( result.isCancelled() )
|
||||
{
|
||||
disconnect( result.getCancelReason() );
|
||||
disconnect( result.getCancelReasonComponents() );
|
||||
return;
|
||||
}
|
||||
if ( ch.isClosed() )
|
||||
|
Loading…
Reference in New Issue
Block a user