mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
More formatting fixes
This commit is contained in:
parent
35c1b26a20
commit
890fac27c5
@ -53,7 +53,7 @@ public abstract class BaseComponent
|
||||
public static String toLegacyText(BaseComponent[] components)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (BaseComponent msg : components)
|
||||
for ( BaseComponent msg : components )
|
||||
{
|
||||
builder.append( msg.toLegacyText() );
|
||||
}
|
||||
@ -63,7 +63,7 @@ public abstract class BaseComponent
|
||||
public static String toPlainText(BaseComponent[] components)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (BaseComponent msg : components)
|
||||
for ( BaseComponent msg : components )
|
||||
{
|
||||
builder.append( msg.toPlainText() );
|
||||
}
|
||||
@ -80,9 +80,9 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public ChatColor getColor()
|
||||
{
|
||||
if (color == null)
|
||||
if ( color == null )
|
||||
{
|
||||
if (parent == null)
|
||||
if ( parent == null )
|
||||
{
|
||||
return ChatColor.WHITE;
|
||||
}
|
||||
@ -111,7 +111,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public boolean isBold()
|
||||
{
|
||||
if (bold == null)
|
||||
if ( bold == null )
|
||||
{
|
||||
return parent != null && parent.isBold();
|
||||
}
|
||||
@ -138,7 +138,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public boolean isItalic()
|
||||
{
|
||||
if (italic == null)
|
||||
if ( italic == null )
|
||||
{
|
||||
return parent != null && parent.isItalic();
|
||||
}
|
||||
@ -165,7 +165,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public boolean isUnderlined()
|
||||
{
|
||||
if (underlined == null)
|
||||
if ( underlined == null )
|
||||
{
|
||||
return parent != null && parent.isUnderlined();
|
||||
}
|
||||
@ -192,7 +192,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public boolean isStrikethrough()
|
||||
{
|
||||
if (strikethrough == null)
|
||||
if ( strikethrough == null )
|
||||
{
|
||||
return parent != null && parent.isStrikethrough();
|
||||
}
|
||||
@ -219,7 +219,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public boolean isObfuscated()
|
||||
{
|
||||
if (obfuscated == null)
|
||||
if ( obfuscated == null )
|
||||
{
|
||||
return parent != null && parent.isObfuscated();
|
||||
}
|
||||
@ -239,7 +239,7 @@ public abstract class BaseComponent
|
||||
|
||||
public void setExtra(List<BaseComponent> components)
|
||||
{
|
||||
for (BaseComponent component : components)
|
||||
for ( BaseComponent component : components )
|
||||
{
|
||||
component.parent = this;
|
||||
}
|
||||
@ -265,7 +265,7 @@ public abstract class BaseComponent
|
||||
*/
|
||||
public void addExtra(BaseComponent component)
|
||||
{
|
||||
if (extra == null)
|
||||
if ( extra == null )
|
||||
{
|
||||
extra = new ArrayList<>();
|
||||
}
|
||||
@ -289,9 +289,9 @@ public abstract class BaseComponent
|
||||
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
if (extra != null)
|
||||
if ( extra != null )
|
||||
{
|
||||
for (BaseComponent e : extra)
|
||||
for ( BaseComponent e : extra )
|
||||
{
|
||||
e.toPlainText( builder );
|
||||
}
|
||||
@ -307,9 +307,9 @@ public abstract class BaseComponent
|
||||
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
if (extra != null)
|
||||
if ( extra != null )
|
||||
{
|
||||
for (BaseComponent e : extra)
|
||||
for ( BaseComponent e : extra )
|
||||
{
|
||||
e.toLegacyText( builder );
|
||||
}
|
||||
|
@ -26,18 +26,18 @@ public class TextComponent extends BaseComponent
|
||||
TextComponent component = new TextComponent();
|
||||
Matcher matcher = url.matcher( message );
|
||||
|
||||
for (int i = 0; i < message.length(); i++)
|
||||
for ( int i = 0; i < message.length(); i++ )
|
||||
{
|
||||
char c = message.charAt( i );
|
||||
if (c == ChatColor.COLOR_CHAR)
|
||||
if ( c == ChatColor.COLOR_CHAR )
|
||||
{
|
||||
i++;
|
||||
c = message.charAt( i );
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
if ( c >= 'A' && c <= 'Z' )
|
||||
{
|
||||
c += 32;
|
||||
}
|
||||
if (builder.length() > 0)
|
||||
if ( builder.length() > 0 )
|
||||
{
|
||||
TextComponent old = component;
|
||||
component = new TextComponent( old );
|
||||
@ -46,7 +46,7 @@ public class TextComponent extends BaseComponent
|
||||
components.add( old );
|
||||
}
|
||||
ChatColor format = ChatColor.getByChar( c );
|
||||
switch (format)
|
||||
switch ( format )
|
||||
{
|
||||
case BOLD:
|
||||
component.setBold( true );
|
||||
@ -73,11 +73,11 @@ public class TextComponent extends BaseComponent
|
||||
continue;
|
||||
}
|
||||
int pos = message.indexOf( ' ', i );
|
||||
if (pos == -1) pos = message.length();
|
||||
if (matcher.region( i, pos ).find())
|
||||
if ( pos == -1 ) pos = message.length();
|
||||
if ( matcher.region( i, pos ).find() )
|
||||
{ //Web link handling
|
||||
|
||||
if (builder.length() > 0)
|
||||
if ( builder.length() > 0 )
|
||||
{
|
||||
TextComponent old = component;
|
||||
component = new TextComponent( old );
|
||||
@ -91,7 +91,7 @@ public class TextComponent extends BaseComponent
|
||||
ClickEvent clickEvent = new ClickEvent();
|
||||
clickEvent.setAction( ClickEvent.Action.OPEN_URL );
|
||||
String urlString = message.substring( i, pos );
|
||||
if (urlString.startsWith( "http" ))
|
||||
if ( urlString.startsWith( "http" ) )
|
||||
{
|
||||
component.setText( urlString );
|
||||
clickEvent.setValue( urlString );
|
||||
@ -108,7 +108,7 @@ public class TextComponent extends BaseComponent
|
||||
}
|
||||
builder.append( c );
|
||||
}
|
||||
if (builder.length() > 0)
|
||||
if ( builder.length() > 0 )
|
||||
{
|
||||
component.setText( builder.toString() );
|
||||
components.add( component );
|
||||
@ -135,11 +135,11 @@ public class TextComponent extends BaseComponent
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
builder.append( getColor() );
|
||||
if (isBold()) builder.append( ChatColor.BOLD );
|
||||
if (isItalic()) builder.append( ChatColor.ITALIC );
|
||||
if (isUnderlined()) builder.append( ChatColor.UNDERLINE );
|
||||
if (isStrikethrough()) builder.append( ChatColor.STRIKETHROUGH );
|
||||
if (isObfuscated()) builder.append( ChatColor.MAGIC );
|
||||
if ( isBold() ) builder.append( ChatColor.BOLD );
|
||||
if ( isItalic() ) builder.append( ChatColor.ITALIC );
|
||||
if ( isUnderlined() ) builder.append( ChatColor.UNDERLINE );
|
||||
if ( isStrikethrough() ) builder.append( ChatColor.STRIKETHROUGH );
|
||||
if ( isObfuscated() ) builder.append( ChatColor.MAGIC );
|
||||
builder.append( text );
|
||||
super.toLegacyText( builder );
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ public class TranslatableComponent extends BaseComponent
|
||||
{
|
||||
setTranslate( translate );
|
||||
this.with = new ArrayList<>();
|
||||
for (Object w : with)
|
||||
for ( Object w : with )
|
||||
{
|
||||
if (w instanceof String)
|
||||
if ( w instanceof String )
|
||||
{
|
||||
this.with.add( new TextComponent( (String) w ) );
|
||||
} else
|
||||
@ -34,7 +34,7 @@ public class TranslatableComponent extends BaseComponent
|
||||
|
||||
public void setWith(List<BaseComponent> components)
|
||||
{
|
||||
for (BaseComponent component : components)
|
||||
for ( BaseComponent component : components )
|
||||
{
|
||||
component.parent = this;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class ServerConnection implements Server
|
||||
@Override
|
||||
public void disconnect(BaseComponent[] reason)
|
||||
{
|
||||
if (!ch.isClosed())
|
||||
if ( !ch.isClosed() )
|
||||
{
|
||||
// TODO: Can we just use a future here?
|
||||
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
|
||||
|
@ -276,12 +276,12 @@ public final class UserConnection implements ProxiedPlayer
|
||||
|
||||
public synchronized void disconnect0(BaseComponent[] reason)
|
||||
{
|
||||
if (ch.getHandle().isActive())
|
||||
if ( ch.getHandle().isActive() )
|
||||
{
|
||||
bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + BaseComponent.toLegacyText( reason ) );
|
||||
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
|
||||
ch.close();
|
||||
if (server != null)
|
||||
if ( server != null )
|
||||
{
|
||||
server.disconnect( "Quitting" );
|
||||
}
|
||||
@ -304,7 +304,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
@Override
|
||||
public void sendMessages(String... messages)
|
||||
{
|
||||
for (String message : messages)
|
||||
for ( String message : messages )
|
||||
{
|
||||
sendMessage( message );
|
||||
}
|
||||
|
@ -15,50 +15,50 @@ public class BaseComponentSerializer
|
||||
|
||||
protected void deserialize(JsonObject object, BaseComponent component, JsonDeserializationContext context)
|
||||
{
|
||||
if (object.has( "color" ))
|
||||
if ( object.has( "color" ) )
|
||||
{
|
||||
component.setColor( ChatColor.valueOf( object.get( "color" ).getAsString().toUpperCase() ) );
|
||||
}
|
||||
if (object.has( "bold" ))
|
||||
if ( object.has( "bold" ) )
|
||||
{
|
||||
component.setBold( object.get( "bold" ).getAsBoolean() );
|
||||
}
|
||||
if (object.has( "italic" ))
|
||||
if ( object.has( "italic" ) )
|
||||
{
|
||||
component.setItalic( object.get( "italic" ).getAsBoolean() );
|
||||
}
|
||||
if (object.has( "underlined" ))
|
||||
if ( object.has( "underlined" ) )
|
||||
{
|
||||
component.setUnderlined( object.get( "underlined" ).getAsBoolean() );
|
||||
}
|
||||
if (object.has( "strikethrough" ))
|
||||
if ( object.has( "strikethrough" ) )
|
||||
{
|
||||
component.setUnderlined( object.get( "strikethrough" ).getAsBoolean() );
|
||||
}
|
||||
if (object.has( "obfuscated" ))
|
||||
if ( object.has( "obfuscated" ) )
|
||||
{
|
||||
component.setUnderlined( object.get( "obfuscated" ).getAsBoolean() );
|
||||
}
|
||||
if (object.has( "extra" ))
|
||||
if ( object.has( "extra" ) )
|
||||
{
|
||||
component.setExtra( Arrays.asList( (BaseComponent[]) context.deserialize( object.get( "extra" ), BaseComponent[].class ) ) );
|
||||
}
|
||||
|
||||
//Events
|
||||
if (object.has( "clickEvent" ))
|
||||
if ( object.has( "clickEvent" ) )
|
||||
{
|
||||
JsonObject event = object.getAsJsonObject( "clickEvent" );
|
||||
component.setClickEvent( new ClickEvent(
|
||||
ClickEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ),
|
||||
event.get( "value" ).getAsString() ) );
|
||||
}
|
||||
if (object.has( "hoverEvent" ))
|
||||
if ( object.has( "hoverEvent" ) )
|
||||
{
|
||||
JsonObject event = object.getAsJsonObject( "hoverEvent" );
|
||||
HoverEvent hoverEvent = new HoverEvent();
|
||||
hoverEvent.setAction( HoverEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ) );
|
||||
Object res = context.deserialize( event.get( "value" ), BaseComponent.class );
|
||||
if (res instanceof String)
|
||||
if ( res instanceof String )
|
||||
{
|
||||
hoverEvent.setValue( (String) res );
|
||||
} else
|
||||
@ -71,44 +71,44 @@ public class BaseComponentSerializer
|
||||
|
||||
protected void serialize(JsonObject object, BaseComponent component, JsonSerializationContext context)
|
||||
{
|
||||
if (component.getColorRaw() != null)
|
||||
if ( component.getColorRaw() != null )
|
||||
{
|
||||
object.addProperty( "color", component.getColorRaw().getName() );
|
||||
}
|
||||
if (component.isBoldRaw() != null)
|
||||
if ( component.isBoldRaw() != null )
|
||||
{
|
||||
object.addProperty( "bold", component.isBoldRaw() );
|
||||
}
|
||||
if (component.isItalicRaw() != null)
|
||||
if ( component.isItalicRaw() != null )
|
||||
{
|
||||
object.addProperty( "italic", component.isItalicRaw() );
|
||||
}
|
||||
if (component.isUnderlinedRaw() != null)
|
||||
if ( component.isUnderlinedRaw() != null )
|
||||
{
|
||||
object.addProperty( "underlined", component.isUnderlinedRaw() );
|
||||
}
|
||||
if (component.isStrikethroughRaw() != null)
|
||||
if ( component.isStrikethroughRaw() != null )
|
||||
{
|
||||
object.addProperty( "strikethrough", component.isStrikethroughRaw() );
|
||||
}
|
||||
if (component.isObfuscatedRaw() != null)
|
||||
if ( component.isObfuscatedRaw() != null )
|
||||
{
|
||||
object.addProperty( "obfuscated", component.isObfuscatedRaw() );
|
||||
}
|
||||
|
||||
if (component.getExtra() != null)
|
||||
if ( component.getExtra() != null )
|
||||
{
|
||||
object.add( "extra", context.serialize( component.getExtra() ) );
|
||||
}
|
||||
|
||||
//Events
|
||||
if (component.getClickEvent() != null)
|
||||
if ( component.getClickEvent() != null )
|
||||
{
|
||||
JsonObject clickEvent = new JsonObject();
|
||||
clickEvent.addProperty( "action", component.getClickEvent().getAction().toString().toLowerCase() );
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
}
|
||||
if (component.getHoverEvent() != null)
|
||||
if ( component.getHoverEvent() != null )
|
||||
{
|
||||
JsonObject clickEvent = new JsonObject();
|
||||
clickEvent.addProperty( "action", component.getHoverEvent().getAction().toString().toLowerCase() );
|
||||
|
@ -26,7 +26,7 @@ public class ComponentSerializer implements JsonSerializer<BaseComponent>, JsonD
|
||||
|
||||
public static BaseComponent[] parse(String json)
|
||||
{
|
||||
if (json.startsWith( "[" ))
|
||||
if ( json.startsWith( "[" ) )
|
||||
{ //Array
|
||||
return gson.fromJson( json, BaseComponent[].class );
|
||||
}
|
||||
@ -46,12 +46,12 @@ public class ComponentSerializer implements JsonSerializer<BaseComponent>, JsonD
|
||||
@Override
|
||||
public BaseComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if (json.isJsonPrimitive())
|
||||
if ( json.isJsonPrimitive() )
|
||||
{
|
||||
return new TextComponent( json.getAsString() );
|
||||
}
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if (object.has( "translate" ))
|
||||
if ( object.has( "translate" ) )
|
||||
{
|
||||
return context.deserialize( json, TranslatableComponent.class );
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class TextComponentSerializer extends BaseComponentSerializer implements
|
||||
@Override
|
||||
public JsonElement serialize(TextComponent src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
if (!src.hasFormatting())
|
||||
if ( !src.hasFormatting() )
|
||||
{
|
||||
return new JsonPrimitive( src.getText() );
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class TranslatableComponentSerializer extends BaseComponentSerializer imp
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
deserialize( object, component, context );
|
||||
component.setTranslate( object.get( "translate" ).getAsString() );
|
||||
if (object.has( "with" ))
|
||||
if ( object.has( "with" ) )
|
||||
{
|
||||
component.setWith( Arrays.asList( (BaseComponent[]) context.deserialize( object.get( "with" ), BaseComponent[].class ) ) );
|
||||
}
|
||||
@ -35,7 +35,7 @@ public class TranslatableComponentSerializer extends BaseComponentSerializer imp
|
||||
JsonObject object = new JsonObject();
|
||||
serialize( object, src, context );
|
||||
object.addProperty( "translate", src.getTranslate() );
|
||||
if (src.getWith() != null)
|
||||
if ( src.getWith() != null )
|
||||
{
|
||||
object.add( "with", context.serialize( src.getWith() ) );
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ConsoleCommandSender implements CommandSender
|
||||
@Override
|
||||
public void sendMessages(String... messages)
|
||||
{
|
||||
for (String message : messages)
|
||||
for ( String message : messages )
|
||||
{
|
||||
sendMessage( message );
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@Override
|
||||
public void disconnect(BaseComponent[] reason)
|
||||
{
|
||||
if (!ch.isClosed())
|
||||
if ( !ch.isClosed() )
|
||||
{
|
||||
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
|
||||
ch.close();
|
||||
|
Loading…
Reference in New Issue
Block a user