Minecraft 1.21.4-pre1 support

This commit is contained in:
md_5
2024-11-23 12:27:38 +11:00
parent f6b40b1186
commit 373dab05ad
10 changed files with 127 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
@@ -129,6 +130,10 @@ public abstract class BaseComponent
{
setColor( component.getColorRaw() );
}
if ( replace || !style.hasShadowColor() )
{
setShadowColor( component.getShadowColorRaw() );
}
if ( replace || !style.hasFont() )
{
setFont( component.getFontRaw() );
@@ -175,6 +180,7 @@ public abstract class BaseComponent
if ( retention == FormatRetention.EVENTS || retention == FormatRetention.NONE )
{
setColor( null );
setShadowColor( null );
setBold( null );
setItalic( null );
setUnderlined( null );
@@ -295,6 +301,46 @@ public abstract class BaseComponent
return style.getColor();
}
/**
* Set this component's shadow color.
*
* @param color the component shadow color, or null to use the default
*/
public void setShadowColor(Color color)
{
this.style.setShadowColor( color );
}
/**
* Returns the shadow color of this component. This uses the parent's shadow color if this
* component doesn't have one. null is returned if no shadow color is found.
*
* @return the shadow color of this component
*/
public Color getShadowColor()
{
if ( !style.hasShadowColor() )
{
if ( parent == null )
{
return null;
}
return parent.getShadowColor();
}
return style.getShadowColor();
}
/**
* Returns the shadow color of this component without checking the parents
* shadow color. May return null
*
* @return the shadow color of this component
*/
public Color getShadowColorRaw()
{
return style.getShadowColor();
}
/**
* Set this component's font.
*
@@ -536,6 +582,10 @@ public abstract class BaseComponent
{
setColor( style.getColor() );
}
if ( style.hasShadowColor() )
{
setShadowColor( style.getShadowColor() );
}
if ( style.hasFont() )
{
setFont( style.getFont() );

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;
import java.awt.Color;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@@ -23,6 +24,10 @@ public final class ComponentStyle implements Cloneable
* {@link ChatColor#color} should not be null).</b>
*/
private ChatColor color;
/**
* The shadow color of this style.
*/
private Color shadowColor;
/**
* The font of this style.
*/
@@ -68,6 +73,26 @@ public final class ComponentStyle implements Cloneable
return ( color != null );
}
/**
* Returns the shadow color of this style. May return null.
*
* @return the shadow color of this style, or null if default color
*/
public Color getShadowColor()
{
return shadowColor;
}
/**
* Returns whether or not this style has a shadow color set.
*
* @return whether a shadow color is set
*/
public boolean hasShadowColor()
{
return ( shadowColor != null );
}
/**
* Returns the font of this style. May return null.
*
@@ -195,7 +220,7 @@ public final class ComponentStyle implements Cloneable
*/
public boolean isEmpty()
{
return color == null && font == null && bold == null
return color == null && shadowColor == null && font == null && bold == null
&& italic == null && underlined == null
&& strikethrough == null && obfuscated == null;
}
@@ -203,7 +228,7 @@ public final class ComponentStyle implements Cloneable
@Override
public ComponentStyle clone()
{
return new ComponentStyle( color, font, bold, italic, underlined, strikethrough, obfuscated );
return new ComponentStyle( color, shadowColor, font, bold, italic, underlined, strikethrough, obfuscated );
}
/**
@@ -227,6 +252,7 @@ public final class ComponentStyle implements Cloneable
{
return new ComponentStyleBuilder()
.color( other.color )
.shadowColor( other.shadowColor )
.font( other.font )
.bold( other.bold )
.italic( other.italic )

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;
import java.awt.Color;
import net.md_5.bungee.api.ChatColor;
/**
@@ -26,6 +27,7 @@ public final class ComponentStyleBuilder
{
private ChatColor color;
private Color shadowColor;
private String font;
private Boolean bold, italic, underlined, strikethrough, obfuscated;
@@ -41,6 +43,18 @@ public final class ComponentStyleBuilder
return this;
}
/**
* Set the style shadow color.
*
* @param shadowColor the shadow color to set, or null to use the default
* @return this ComponentStyleBuilder for chaining
*/
public ComponentStyleBuilder shadowColor(Color shadowColor)
{
this.shadowColor = shadowColor;
return this;
}
/**
* Set the style font.
*
@@ -121,6 +135,6 @@ public final class ComponentStyleBuilder
*/
public ComponentStyle build()
{
return new ComponentStyle( color, font, bold, italic, underlined, strikethrough, obfuscated );
return new ComponentStyle( color, shadowColor, font, bold, italic, underlined, strikethrough, obfuscated );
}
}

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.chat;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@@ -8,6 +9,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.awt.Color;
import java.lang.reflect.Type;
import java.util.Map;
import net.md_5.bungee.api.ChatColor;
@@ -67,6 +69,10 @@ public class ComponentStyleSerializer implements JsonSerializer<ComponentStyle>,
{
object.addProperty( "color", style.getColor().getName() );
}
if ( style.hasShadowColor() )
{
object.addProperty( "shadow_color", style.getShadowColor().getRGB() );
}
if ( style.hasFont() )
{
object.addProperty( "font", style.getFont() );
@@ -102,6 +108,17 @@ public class ComponentStyleSerializer implements JsonSerializer<ComponentStyle>,
case "color":
builder.color( ChatColor.of( value.getAsString() ) );
break;
case "shadow_color":
if ( value.isJsonArray() )
{
JsonArray array = value.getAsJsonArray();
builder.shadowColor( new Color( array.get( 0 ).getAsFloat(), array.get( 1 ).getAsFloat(), array.get( 2 ).getAsFloat(), array.get( 3 ).getAsFloat() ) );
} else if ( value.isJsonPrimitive() )
{
builder.shadowColor( new Color( value.getAsNumber().intValue(), true ) );
}
break;
case "font":
builder.font( value.getAsString() );
break;