#3874: Add ObjectComponents
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package net.md_5.bungee.api.chat;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.chat.objects.ChatObject;
|
||||
|
||||
/**
|
||||
* An object component that can be used to display objects.
|
||||
* <p>
|
||||
* It can either display a player's head or an object by a specific sprite and
|
||||
* an atlas.
|
||||
* <p>
|
||||
* Note: this was added in Minecraft 1.21.9.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class ObjectComponent extends BaseComponent
|
||||
{
|
||||
|
||||
private ChatObject object;
|
||||
|
||||
/**
|
||||
* Creates a ObjectComponent from a given ChatObject.
|
||||
*
|
||||
* See {@link net.md_5.bungee.api.chat.objects.PlayerObject} and
|
||||
* {@link net.md_5.bungee.api.chat.objects.SpriteObject}.
|
||||
*
|
||||
* @param object the ChatObject
|
||||
*/
|
||||
public ObjectComponent(@NonNull ChatObject object)
|
||||
{
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object component from the original to clone it.
|
||||
*
|
||||
* @param original the original for the new score component
|
||||
*/
|
||||
public ObjectComponent(ObjectComponent original)
|
||||
{
|
||||
super( original );
|
||||
setObject( original.object );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectComponent duplicate()
|
||||
{
|
||||
return new ObjectComponent( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
{
|
||||
// I guess we cannot convert this to plain text
|
||||
// builder.append( this.value );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
// Same here...
|
||||
// builder.append( this.value );
|
||||
super.toLegacyText( builder );
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
public interface ChatObject
|
||||
{
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import net.md_5.bungee.api.chat.player.Profile;
|
||||
import net.md_5.bungee.api.chat.player.Property;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public final class PlayerObject implements ChatObject
|
||||
{
|
||||
|
||||
/**
|
||||
* The profile of the player.
|
||||
*/
|
||||
@NonNull
|
||||
private Profile profile;
|
||||
/**
|
||||
* If true, a hat layer will be rendered on the head. (default: true)
|
||||
*/
|
||||
private Boolean hat;
|
||||
|
||||
public PlayerObject(@NonNull String name)
|
||||
{
|
||||
this.profile = new Profile( name );
|
||||
}
|
||||
|
||||
public PlayerObject(@NonNull UUID uuid)
|
||||
{
|
||||
this.profile = new Profile( uuid );
|
||||
}
|
||||
|
||||
public PlayerObject(@NonNull Property[] properties)
|
||||
{
|
||||
this.profile = new Profile( properties );
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public final class SpriteObject implements ChatObject
|
||||
{
|
||||
|
||||
/**
|
||||
* The namespaced ID of a sprite atlas, default value: minecraft:blocks.
|
||||
*/
|
||||
private String atlas;
|
||||
/**
|
||||
* The namespaced ID of a sprite in atlas, for example item/porkchop.
|
||||
*/
|
||||
@NonNull
|
||||
private String sprite;
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package net.md_5.bungee.api.chat.player;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Profile
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the profile. Can be null.
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* The UUID of the profile. Can be null.
|
||||
*/
|
||||
private UUID uuid;
|
||||
/**
|
||||
* The properties of the profile. Can be null.
|
||||
*/
|
||||
private Property[] properties;
|
||||
|
||||
public Profile(@NonNull String name)
|
||||
{
|
||||
this( name, null, null );
|
||||
}
|
||||
|
||||
public Profile(@NonNull UUID uuid)
|
||||
{
|
||||
this( null, uuid, null );
|
||||
}
|
||||
|
||||
public Profile(@NonNull Property[] properties)
|
||||
{
|
||||
this( null, null, properties );
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package net.md_5.bungee.api.chat.player;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Property
|
||||
{
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
@NonNull
|
||||
private String value;
|
||||
private String signature;
|
||||
|
||||
public Property(@NonNull String name, @NonNull String value)
|
||||
{
|
||||
this( name, value, null );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user