Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #107 from SpigotMC/master
Browse files Browse the repository at this point in the history
Merge with SpigotMC
  • Loading branch information
sleiss authored Dec 1, 2016
2 parents 0df78e3 + ea66802 commit 708ac94
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
34 changes: 33 additions & 1 deletion api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
*/
Expand All @@ -34,4 +39,31 @@ public LoginEvent(PendingConnection connection, Callback<LoginEvent> done)
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;
}
}
34 changes: 33 additions & 1 deletion api/src/main/java/net/md_5/bungee/api/event/PreLoginEvent.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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.
*/
Expand All @@ -39,4 +44,31 @@ public PreLoginEvent(PendingConnection connection, Callback<PreLoginEvent> done)
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;
}
}
4 changes: 2 additions & 2 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public void sendMessage(ChatMessageType position, BaseComponent... message)
// Action bar on 1.8 doesn't display the new JSON formattings, legacy works - send it using this for now
if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 )
{
sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) );
sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) );
} else
{
sendMessage( position, ComponentSerializer.toString( message ) );
Expand All @@ -448,7 +448,7 @@ public void sendMessage(ChatMessageType position, BaseComponent message)
// Action bar on 1.8 doesn't display the new JSON formattings, legacy works - send it using this for now
if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 )
{
sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) );
sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) );
} else
{
sendMessage( position, ComponentSerializer.toString( message ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void done(PreLoginEvent result, Throwable error)
{
if ( result.isCancelled() )
{
disconnect( result.getCancelReason() );
disconnect( result.getCancelReasonComponents() );
return;
}
if ( ch.isClosed() )
Expand Down Expand Up @@ -479,7 +479,7 @@ public void done(LoginEvent result, Throwable error)
{
if ( result.isCancelled() )
{
disconnect( result.getCancelReason() );
disconnect( result.getCancelReasonComponents() );
return;
}
if ( ch.isClosed() )
Expand Down

0 comments on commit 708ac94

Please sign in to comment.