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

Commit

Permalink
Merge branch 'SpigotMC-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sleiss committed Sep 18, 2017
2 parents 5ad69c7 + 4e72f8d commit 2264ef9
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 48 deletions.
36 changes: 24 additions & 12 deletions chat/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,25 @@ public abstract class BaseComponent

BaseComponent(BaseComponent old)
{
setColor( old.getColorRaw() );
setBold( old.isBoldRaw() );
setItalic( old.isItalicRaw() );
setUnderlined( old.isUnderlinedRaw() );
setStrikethrough( old.isStrikethroughRaw() );
setObfuscated( old.isObfuscatedRaw() );
setInsertion( old.getInsertion() );
setClickEvent( old.getClickEvent() );
setHoverEvent( old.getHoverEvent() );
if ( old.getExtra() != null )
copyFormatting( old );
}

public void copyFormatting( BaseComponent component )
{
setColor( component.getColorRaw() );
setBold( component.isBoldRaw() );
setItalic( component.isItalicRaw() );
setUnderlined( component.isUnderlinedRaw() );
setStrikethrough( component.isStrikethroughRaw() );
setObfuscated( component.isObfuscatedRaw() );
setInsertion( component.getInsertion() );
setClickEvent( component.getClickEvent() );
setHoverEvent( component.getHoverEvent() );
if ( component.getExtra() != null )
{
for ( BaseComponent component : old.getExtra() )
for ( BaseComponent extra : component.getExtra() )
{
addExtra( component.duplicate() );
addExtra( extra.duplicate() );
}
}
}
Expand All @@ -101,6 +106,13 @@ public abstract class BaseComponent
*/
public abstract BaseComponent duplicate();

/**
* Clones the BaseComponent without formatting and returns the clone.
*
* @return The duplicate of this BaseComponent
*/
public abstract BaseComponent duplicateWithoutFormatting();

/**
* Converts the components to a string that uses the old formatting codes
* ({@link net.md_5.bungee.api.ChatColor#COLOR_CHAR}
Expand Down
27 changes: 6 additions & 21 deletions chat/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ComponentBuilder
*/
public ComponentBuilder(ComponentBuilder original)
{
current = new TextComponent( original.current );
current = original.current.duplicate();
for ( BaseComponent baseComponent : original.parts )
{
parts.add( baseComponent.duplicate() );
Expand Down Expand Up @@ -113,8 +113,9 @@ public ComponentBuilder append(String text, FormatRetention retention)
{
parts.add( current );

current = new TextComponent( (TextComponent) current );
( (TextComponent) current ).setText( text );
BaseComponent old = current;
current = new TextComponent( text );
current.copyFormatting( old );
retain( retention );

return this;
Expand Down Expand Up @@ -251,29 +252,13 @@ public ComponentBuilder retain(FormatRetention retention)
switch ( retention )
{
case NONE:
if ( current instanceof TextComponent )
{
current = new TextComponent( ( (TextComponent) current ).getText() );
} else if ( current instanceof TranslatableComponent )
{
TranslatableComponent oldComponent = (TranslatableComponent) current;
current = new TranslatableComponent( oldComponent.getTranslate(), oldComponent.getWith() );
}

current = current.duplicateWithoutFormatting();
break;
case ALL:
// No changes are required
break;
case EVENTS:
if ( current instanceof TextComponent )
{
current = new TextComponent( ( (TextComponent) current ).getText() );
} else if ( current instanceof TranslatableComponent )
{
TranslatableComponent oldComponent = (TranslatableComponent) current;
current = new TranslatableComponent( oldComponent.getTranslate(), oldComponent.getWith() );
}

current = current.duplicateWithoutFormatting();
current.setInsertion( previous.getInsertion() );
current.setClickEvent( previous.getClickEvent() );
current.setHoverEvent( previous.getHoverEvent() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ public BaseComponent duplicate()
return new TextComponent( this );
}

@Override
public BaseComponent duplicateWithoutFormatting()
{
return new TextComponent( this.text );
}

@Override
protected void toPlainText(StringBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ public TranslatableComponent(TranslatableComponent original)
public TranslatableComponent(String translate, Object... with)
{
setTranslate( translate );
List<BaseComponent> temp = new ArrayList<BaseComponent>();
for ( Object w : with )
if ( with != null && with.length != 0 )
{
if ( w instanceof String )
{
temp.add( new TextComponent( (String) w ) );
} else
List<BaseComponent> temp = new ArrayList<BaseComponent>();
for ( Object w : with )
{
temp.add( (BaseComponent) w );
if ( w instanceof String )
{
temp.add( new TextComponent( (String) w ) );
} else
{
temp.add( (BaseComponent) w );
}
}
setWith( temp );
}
setWith( temp );
}

/**
Expand All @@ -91,6 +94,12 @@ public BaseComponent duplicate()
return new TranslatableComponent( this );
}

@Override
public BaseComponent duplicateWithoutFormatting()
{
return new TranslatableComponent( this.translate, this.with );
}

/**
* Sets the translation substitutions to be used in this component. Removes
* any previously set substitutions
Expand Down
3 changes: 3 additions & 0 deletions protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ public static class DirectionData
linkedProtocols.put( ProtocolConstants.MINECRAFT_1_12, Arrays.asList(
ProtocolConstants.MINECRAFT_1_12_1
) );
linkedProtocols.put( ProtocolConstants.MINECRAFT_1_12_1, Arrays.asList(
ProtocolConstants.MINECRAFT_1_12_2
) );
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_11_1 = 316;
public static final int MINECRAFT_1_12 = 335;
public static final int MINECRAFT_1_12_1 = 338;
public static final int MINECRAFT_1_12_2 = 340;
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"1.7.x",
"1.8.x",
Expand All @@ -38,7 +39,8 @@ public class ProtocolConstants
ProtocolConstants.MINECRAFT_1_11,
ProtocolConstants.MINECRAFT_1_11_1,
ProtocolConstants.MINECRAFT_1_12,
ProtocolConstants.MINECRAFT_1_12_1
ProtocolConstants.MINECRAFT_1_12_1,
ProtocolConstants.MINECRAFT_1_12_2
);

public enum Direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
public class KeepAlive extends DefinedPacket
{

private int randomId;
private long randomId;

@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_12_2 )
{
randomId = buf.readLong();
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
randomId = readVarInt( buf );
} else
Expand All @@ -33,12 +36,15 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_12_2 )
{
buf.writeLong( randomId );
} else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
writeVarInt( randomId, buf );
writeVarInt( (int) randomId, buf );
} else
{
buf.writeInt( randomId );
buf.writeInt( (int) randomId );
}
}

Expand Down
2 changes: 1 addition & 1 deletion proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final class UserConnection implements ProxiedPlayer
/*========================================================================*/
@Getter
@Setter
private int sentPingId;
private long sentPingId;
@Getter
@Setter
private long sentPingTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static EntityMap getEntityMap(int version)
case ProtocolConstants.MINECRAFT_1_12:
return EntityMap_1_12.INSTANCE;
case ProtocolConstants.MINECRAFT_1_12_1:
case ProtocolConstants.MINECRAFT_1_12_2:
return EntityMap_1_12_1.INSTANCE;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
Expand Down
9 changes: 9 additions & 0 deletions proxy/src/test/java/net/md_5/bungee/chat/ComponentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
public class ComponentsTest
{

@Test
public void testBuilderClone()
{
ComponentBuilder builder = new ComponentBuilder("Hel").color(ChatColor.RED).append("lo").color(ChatColor.DARK_RED);
ComponentBuilder cloned = new ComponentBuilder( builder );

Assert.assertEquals( TextComponent.toLegacyText( builder.create() ), TextComponent.toLegacyText( cloned.create() ) );
}

@Test
public void testBuilderAppend()
{
Expand Down

0 comments on commit 2264ef9

Please sign in to comment.