Skip to content

Commit

Permalink
Replace remaining instantes of #fromLegacyText() with #fromLegacy()
Browse files Browse the repository at this point in the history
  • Loading branch information
2008Choco committed Oct 26, 2023
1 parent aaaae41 commit 281710b
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 43 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/net/md_5/bungee/api/ServerPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public static class ModItem
@Deprecated
public ServerPing(Protocol version, Players players, String description, String favicon)
{
this( version, players, new TextComponent( TextComponent.fromLegacyText( description ) ), favicon == null ? null : Favicon.create( favicon ) );
this( version, players, TextComponent.fromLegacy( description ), favicon == null ? null : Favicon.create( favicon ) );
}

@Deprecated
public ServerPing(Protocol version, Players players, String description, Favicon favicon)
{
this( version, players, new TextComponent( TextComponent.fromLegacyText( description ) ), favicon );
this( version, players, TextComponent.fromLegacy( description ), favicon );
}

@Deprecated
Expand Down Expand Up @@ -139,7 +139,7 @@ public void setFavicon(Favicon favicon)
@Deprecated
public void setDescription(String description)
{
this.description = new TextComponent( TextComponent.fromLegacyText( description ) );
this.description = TextComponent.fromLegacy( description );
}

@Deprecated
Expand Down
33 changes: 22 additions & 11 deletions api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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.ComponentBuilder;
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 @@ -27,8 +26,7 @@ public class LoginEvent extends AsyncEvent<LoginEvent> implements Cancellable
/**
* Message to use when kicking if this event is canceled.
*/
@Setter(AccessLevel.NONE)
private BaseComponent[] cancelReasonComponents;
private BaseComponent reason;
/**
* Connection attempting to login.
*/
Expand All @@ -42,28 +40,41 @@ public LoginEvent(PendingConnection connection, Callback<LoginEvent> done)

/**
* @return reason to be displayed
* @deprecated Use component methods instead.
* @deprecated Use {@link #getReason()} instead
*/
@Deprecated
public String getCancelReason()
{
return BaseComponent.toLegacyText( getCancelReasonComponents() );
return TextComponent.toLegacyText( getReason() );
}

/**
* @param cancelReason reason to be displayed
* @deprecated Use
* {@link #setCancelReason(net.md_5.bungee.api.chat.BaseComponent...)}
* instead.
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setCancelReason(String cancelReason)
{
setCancelReason( TextComponent.fromLegacyText( cancelReason ) );
setReason( TextComponent.fromLegacy( cancelReason ) );
}

/**
* @return the cancel reason
* @deprecated Use {@link #getCancelReason()} instead.
*/
@Deprecated
public BaseComponent[] getCancelReasonComponents()
{
return new BaseComponent[] {getReason()};
}

/**
* @param cancelReason the cancel reason
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setCancelReason(BaseComponent... cancelReason)
{
this.cancelReasonComponents = cancelReason;
setReason( new ComponentBuilder().append( cancelReason ).build() );
}
}
33 changes: 22 additions & 11 deletions api/src/main/java/net/md_5/bungee/api/event/PreLoginEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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.ComponentBuilder;
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 @@ -32,8 +31,7 @@ public class PreLoginEvent extends AsyncEvent<PreLoginEvent> implements Cancella
/**
* Message to use when kicking if this event is canceled.
*/
@Setter(AccessLevel.NONE)
private BaseComponent[] cancelReasonComponents;
private BaseComponent reason;
/**
* Connection attempting to login.
*/
Expand All @@ -47,28 +45,41 @@ public PreLoginEvent(PendingConnection connection, Callback<PreLoginEvent> done)

/**
* @return reason to be displayed
* @deprecated Use component methods instead.
* @deprecated use {@link #getReason()} instead
*/
@Deprecated
public String getCancelReason()
{
return BaseComponent.toLegacyText( getCancelReasonComponents() );
return BaseComponent.toLegacyText( getReason() );
}

/**
* @param cancelReason reason to be displayed
* @deprecated Use
* {@link #setCancelReason(net.md_5.bungee.api.chat.BaseComponent...)}
* instead.
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setCancelReason(String cancelReason)
{
setCancelReason( TextComponent.fromLegacyText( cancelReason ) );
setReason( TextComponent.fromLegacy( cancelReason ) );
}

/**
* @return the cancel reason
* @deprecated Use {@link #getReason()} instead
*/
@Deprecated
public BaseComponent[] getCancelReasonComponents()
{
return new BaseComponent[] {getReason()};
}

/**
* @param cancelReason the cancel reason
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setCancelReason(BaseComponent... cancelReason)
{
this.cancelReasonComponents = cancelReason;
setReason( new ComponentBuilder().append( cancelReason ).build() );
}
}
43 changes: 39 additions & 4 deletions api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class ServerKickEvent extends Event implements Cancellable
/**
* Kick reason.
*/
private BaseComponent[] kickReasonComponent;
private BaseComponent reason;
/**
* Server to send player to if this event is cancelled.
*/
Expand Down Expand Up @@ -63,24 +64,58 @@ public ServerKickEvent(ProxiedPlayer player, BaseComponent[] kickReasonComponent
this( player, player.getServer().getInfo(), kickReasonComponent, cancelServer, state );
}

@Deprecated
public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent[] kickReasonComponent, ServerInfo cancelServer, State state)
{
this( player, kickedFrom, new ComponentBuilder().append( kickReasonComponent ).build(), cancelServer, state );
}

public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent reason, ServerInfo cancelServer, State state)
{
this.player = player;
this.kickedFrom = kickedFrom;
this.kickReasonComponent = kickReasonComponent;
this.reason = reason;
this.cancelServer = cancelServer;
this.state = state;
}

/**
* @return the kick reason
* @deprecated Use {@link #getReason()} instead
*/
@Deprecated
public String getKickReason()
{
return BaseComponent.toLegacyText( kickReasonComponent );
return BaseComponent.toLegacyText( getReason() );
}

/**
* @param reason the kick reason
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setKickReason(String reason)
{
kickReasonComponent = TextComponent.fromLegacyText( reason );
this.setReason( TextComponent.fromLegacy( reason ) );
}

/**
* @return the kick reason
* @deprecated Use {@link #getReason()} instead
*/
@Deprecated
public BaseComponent[] getKickReasonComponent()
{
return new BaseComponent[] {getReason()};
}

/**
* @param kickReasonComponent the kick reason
* @deprecated Use {@link #setReason(BaseComponent)} instead
*/
@Deprecated
public void setKickReasonComponent(BaseComponent[] kickReasonComponent)
{
this.setReason( new ComponentBuilder().append( kickReasonComponent ).build() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(CommandSender sender, String[] args)

String message = builder.substring( 0, builder.length() - 1 );

ProxyServer.getInstance().broadcast( TextComponent.fromLegacyText( message ) );
ProxyServer.getInstance().broadcast( TextComponent.fromLegacy( message ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public void execute(CommandSender sender, String[] args)

if ( player == null )
{
sender.sendMessage( TextComponent.fromLegacyText( ProxyServer.getInstance().getTranslation( "user_not_online" ) ) );
sender.sendMessage( TextComponent.fromLegacy( ProxyServer.getInstance().getTranslation( "user_not_online" ) ) );
return;
}

if ( args.length == 1 )
{
player.disconnect( TextComponent.fromLegacyText( ProxyServer.getInstance().getTranslation( "kick_message" ) ) );
player.disconnect( TextComponent.fromLegacy( ProxyServer.getInstance().getTranslation( "kick_message" ) ) );
} else
{
String[] reason = new String[ args.length - 1 ];
System.arraycopy( args, 1, reason, 0, reason.length );
player.disconnect( TextComponent.fromLegacyText( ChatColor.translateAlternateColorCodes( '&', Joiner.on( ' ' ).join( reason ) ) ) );
player.disconnect( TextComponent.fromLegacy( ChatColor.translateAlternateColorCodes( '&', Joiner.on( ' ' ).join( reason ) ) ) );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,13 @@ public CommandSender getConsole()
@Override
public void broadcast(String message)
{
broadcast( TextComponent.fromLegacyText( message ) );
broadcast( TextComponent.fromLegacy( message ) );
}

@Override
public void broadcast(BaseComponent... message)
{
getConsole().sendMessage( BaseComponent.toLegacyText( message ) );
getConsole().sendMessage( message );
for ( ProxiedPlayer player : getPlayers() )
{
player.sendMessage( message );
Expand All @@ -746,7 +746,7 @@ public void broadcast(BaseComponent... message)
@Override
public void broadcast(BaseComponent message)
{
getConsole().sendMessage( message.toLegacyText() );
getConsole().sendMessage( message );
for ( ProxiedPlayer player : getPlayers() )
{
player.sendMessage( message );
Expand Down
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 @@ -407,7 +407,7 @@ private String connectionFailMessage(Throwable cause)
@Override
public void disconnect(String reason)
{
disconnect( TextComponent.fromLegacyText( reason ) );
disconnect( TextComponent.fromLegacy( reason ) );
}

@Override
Expand Down Expand Up @@ -455,7 +455,7 @@ public void chat(String message)
@Override
public void sendMessage(String message)
{
sendMessage( TextComponent.fromLegacyText( message ) );
sendMessage( TextComponent.fromLegacy( message ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ public void done(PreLoginEvent result, Throwable error)
{
if ( result.isCancelled() )
{
BaseComponent[] reason = result.getCancelReasonComponents();
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacyText( bungee.getTranslation( "kick_message" ) ) );
BaseComponent reason = result.getReason();
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacy( bungee.getTranslation( "kick_message" ) ) );
return;
}
if ( ch.isClosed() )
Expand Down Expand Up @@ -578,8 +578,8 @@ public void done(LoginEvent result, Throwable error)
{
if ( result.isCancelled() )
{
BaseComponent[] reason = result.getCancelReasonComponents();
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacyText( bungee.getTranslation( "kick_message" ) ) );
BaseComponent reason = result.getReason();
disconnect( ( reason != null ) ? reason : TextComponent.fromLegacy( bungee.getTranslation( "kick_message" ) ) );
return;
}
if ( ch.isClosed() )
Expand Down Expand Up @@ -646,7 +646,7 @@ public void disconnect(String reason)
{
if ( canSendKickMessage() )
{
disconnect( TextComponent.fromLegacyText( reason ) );
disconnect( TextComponent.fromLegacy( reason ) );
} else
{
ch.close();
Expand Down

0 comments on commit 281710b

Please sign in to comment.