Skip to content

Commit

Permalink
Fix some compatibility packet getters and setters not being null-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
Janmm14 committed Mar 18, 2024
1 parent 7d438f6 commit 9d433c5
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,20 @@ public void handle(AbstractPacketHandler handler) throws Exception

public BaseComponent getTitle()
{
if ( title == null )
{
return null;
}
return title.get();
}

public void setTitle(BaseComponent title)
{
if ( title == null )
{
this.title = null;
return;
}
this.title = new NoOrigDeserializable<>( title );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ public Kick(BaseComponent message)

public BaseComponent getMessage()
{
if ( messageRaw == null )
{
return null;
}
return messageRaw.get();
}

public void setMessage(BaseComponent message)
{
if ( message == null )
{
this.messageRaw = null;
return;
}
this.messageRaw = new NoOrigDeserializable<>( message );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,39 @@ public PlayerListHeaderFooter(BaseComponent header, BaseComponent footer)

public BaseComponent getHeader()
{
if ( headerRaw == null )
{
return null;
}
return headerRaw.get();
}

public void setHeader(BaseComponent header)
{
if ( header == null )
{
this.headerRaw = null;
return;
}
this.headerRaw = new NoOrigDeserializable<>( header );
}

public BaseComponent getFooter()
{
if ( footerRaw == null )
{
return null;
}
return footerRaw.get();
}

public void setFooter(BaseComponent footer)
{
if ( footer == null )
{
this.footerRaw = null;
return;
}
this.footerRaw = new NoOrigDeserializable<>( footer );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,20 @@ public static class Item

public BaseComponent getDisplayName()
{
if ( displayNameRaw == null )
{
return null;
}
return displayNameRaw.get();
}

public void setDisplayName(BaseComponent displayName)
{
if ( displayName == null )
{
this.displayNameRaw = null;
return;
}
this.displayNameRaw = new NoOrigDeserializable<>( displayName );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,20 @@ public ServerData(BaseComponent motd, Object icon, boolean preview, boolean enfo

public BaseComponent getMotd()
{
if ( motdRaw == null )
{
return null;
}
return motdRaw.get();
}

public void setMotd(BaseComponent motd)
{
if ( motd == null )
{
this.motdRaw = null;
return;
}
this.motdRaw = new NoOrigDeserializable<>( motd );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ public Subtitle(BaseComponent text)

public BaseComponent getText()
{
if ( textRaw == null )
{
return null;
}
return textRaw.get();
}

public void setText(BaseComponent text)
{
if ( text == null )
{
this.textRaw = null;
return;
}
this.textRaw = new NoOrigDeserializable<>( text );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ public SystemChat(BaseComponent message, int position)

public BaseComponent getMessage()
{
if ( messageRaw == null )
{
return null;
}
return messageRaw.get();
}

public void setMessage(BaseComponent message)
{
if ( message == null )
{
this.messageRaw = null;
return;
}
this.messageRaw = new NoOrigDeserializable<>( message );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ private static class ComponentMessage implements Message

public BaseComponent getComponent()
{
if ( componentRaw == null )
{
return null;
}
return componentRaw.get();
}

Expand Down
27 changes: 27 additions & 0 deletions protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
@SuppressWarnings("unchecked")
public Either<String, BaseComponent> getDisplayName()
{
if ( displayNameRaw == null )
{
return null;
}
if ( displayNameRaw.isLeft() )
{
return (Either) displayNameRaw;
Expand All @@ -141,6 +145,11 @@ public Either<String, BaseComponent> getDisplayName()
@SuppressWarnings("unchecked")
public void setDisplayName(Either<String, BaseComponent> displayName)
{
if ( displayName == null )
{
displayNameRaw = null;
return;
}
if ( displayName.isLeft() )
{
displayNameRaw = (Either) displayName;
Expand All @@ -153,6 +162,10 @@ public void setDisplayName(Either<String, BaseComponent> displayName)
@SuppressWarnings("unchecked")
public Either<String, BaseComponent> getPrefix()
{
if ( prefixRaw == null )
{
return null;
}
if ( prefixRaw.isLeft() )
{
return (Either) prefixRaw;
Expand All @@ -165,6 +178,11 @@ public Either<String, BaseComponent> getPrefix()
@SuppressWarnings("unchecked")
public void setPrefix(Either<String, BaseComponent> prefix)
{
if ( prefix == null )
{
prefixRaw = null;
return;
}
if ( prefix.isLeft() )
{
prefixRaw = (Either) prefix;
Expand All @@ -177,6 +195,10 @@ public void setPrefix(Either<String, BaseComponent> prefix)
@SuppressWarnings("unchecked")
public Either<String, BaseComponent> getSuffix()
{
if ( suffixRaw == null )
{
return null;
}
if ( suffixRaw.isLeft() )
{
return (Either) suffixRaw;
Expand All @@ -189,6 +211,11 @@ public Either<String, BaseComponent> getSuffix()
@SuppressWarnings("unchecked")
public void setSuffix(Either<String, BaseComponent> suffix)
{
if ( suffix == null )
{
suffixRaw = null;
return;
}
if ( suffix.isLeft() )
{
suffixRaw = (Either) suffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,20 @@ public Title(Action action, BaseComponent text, int fadeIn, int stay, int fadeOu

public BaseComponent getText()
{
if ( textRaw == null )
{
return null;
}
return textRaw.get();
}

public void setText(BaseComponent text)
{
if ( text == null )
{
this.textRaw = null;
return;
}
this.textRaw = new NoOrigDeserializable<>( text );
}
}

0 comments on commit 9d433c5

Please sign in to comment.