Skip to content

Commit

Permalink
Upstream update & optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
RealSuperUser committed Feb 9, 2025
1 parent 53ebbc2 commit 0d30189
Show file tree
Hide file tree
Showing 21 changed files with 1,010 additions and 636 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void setStyle(ComponentStyle style) {
* Set this component's color.
* <p>
* <b>Warning: This should be a color, not formatting code (ie,
* {@link ChatColor#color} should not be null).</b>
* {@link ChatColor#(ChatColor)} should not be null).</b>
*
* @param color the component color, or null to use the default
*/
Expand Down
6 changes: 6 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.ApiStatus;
import lombok.Setter;

@Getter
@ToString
Expand All @@ -22,6 +24,10 @@ public final class ClickEvent {
*/
private final String value;

@Setter
@ApiStatus.Internal
private boolean v1_21_5 = false;

public enum Action {

/**
Expand Down
26 changes: 26 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Collections;
import java.util.List;

import org.jetbrains.annotations.ApiStatus;

@Getter
@ToString
@EqualsAndHashCode
Expand All @@ -30,8 +32,32 @@ public final class HoverEvent {
* Returns whether this hover event is prior to 1.16
*/
@Setter
@ApiStatus.Internal
private boolean legacy = false;

/**
* Returns whether this hover event is used for version above 1.21.4
*/
@ApiStatus.Internal
private boolean v1_21_5 = false;
/**
* Set the compatibility to 1.21.5, also modifies the underlying entities.
*
* @param v1_21_5 the compatibility to set
*/
@ApiStatus.Internal
public void setV1_21_5(boolean v1_21_5)
{
this.v1_21_5 = v1_21_5;
for ( Content content : contents )
{
if ( content instanceof Entity )
{
( (Entity) content ).setV1_21_5( v1_21_5 );
}
}
}

/**
* Creates event with an action and a list of contents.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
import lombok.*;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.HoverEvent;
import org.jetbrains.annotations.ApiStatus;

@Data
@AllArgsConstructor
@ToString
@EqualsAndHashCode(callSuper = true)
public class Entity extends Content {


/**
* Required for backwards compatibility.
*
* @param type the type of the entity, for example 'minecraft:pig'
* @param id for example '6cb1b229-ce5c-4179-af8d-eea185c25963'
* @param name the name of the entity
*/
public Entity(String type, @NonNull String id, BaseComponent name)
{
this( type, id, name, false );
}

/**
* Namespaced entity ID.
* <p>
Expand All @@ -30,6 +44,13 @@ public class Entity extends Content {
*/
private BaseComponent name;

/**
* True if this entity is for 1.21.5 or later
*/
@ApiStatus.Internal
private boolean v1_21_5;


@Override
public HoverEvent.Action requiredAction() {
return HoverEvent.Action.SHOW_ENTITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ public class EntitySerializer implements JsonSerializer<Entity>, JsonDeserialize
public Entity deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject value = element.getAsJsonObject();

String idString;
JsonElement id = value.get("id");
if (id.isJsonArray()) {
idString = parseUUID(context.deserialize(id, int[].class)).toString();
} else {
idString = id.getAsString();
}
boolean newEntity = value.has( "uuid" );

return new Entity(
(value.has("type")) ? value.get("type").getAsString() : null,
idString,
(value.has("name")) ? context.deserialize(value.get("name"), BaseComponent.class) : null
String idString;
JsonElement uuid = value.get( newEntity ? "uuid" : "id" );
if ( uuid.isJsonArray() ){
idString = parseUUID( context.deserialize( uuid, int[].class ) ).toString();
} else
{
idString = uuid.getAsString();
}
return new Entity( ( value.has( newEntity ? "id" : "type" ) ) ? value.get( newEntity ? "id" : "type" ).getAsString() : null,
idString, ( value.has( "name" ) ) ? context.deserialize( value.get( "name" ), BaseComponent.class ) : null,
newEntity
);
}

@Override
public JsonElement serialize(Entity content, Type type, JsonSerializationContext context) {
JsonObject object = new JsonObject();
object.addProperty("type", (content.getType() != null) ? content.getType() : "minecraft:pig");
object.addProperty("id", content.getId());
object.addProperty( content.isV1_21_5() ? "id" : "type", ( content.getType() != null ) ? content.getType() : "minecraft:pig" );
object.addProperty( content.isV1_21_5() ? "uuid" : "id", content.getId() );
if (content.getName() != null) {
object.add("name", context.serialize(content.getName()));
}
Expand Down
Loading

0 comments on commit 0d30189

Please sign in to comment.