Skip to content

Commit

Permalink
Merge pull request #288 from KyoriPowered/feature/hover-overloads
Browse files Browse the repository at this point in the history
api: Add Keyed overloads to hover event types
  • Loading branch information
zml2008 authored Feb 26, 2021
2 parents 1226559 + a94d6b5 commit 5ffdd94
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/event/HoverEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.kyori.adventure.nbt.api.BinaryTagHolder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
Expand Down Expand Up @@ -88,6 +89,18 @@ public final class HoverEvent<V> implements Examinable, HoverEventSource<V>, Sty
return showItem(item, count, null);
}

/**
* Creates a hover event that shows an item on hover.
*
* @param item the item
* @param count the count
* @return a hover event
* @since 4.6.0
*/
public static @NonNull HoverEvent<ShowItem> showItem(final @NonNull Keyed item, final @NonNegative int count) {
return showItem(item, count, null);
}

/**
* Creates a hover event that shows an item on hover.
*
Expand All @@ -101,6 +114,19 @@ public final class HoverEvent<V> implements Examinable, HoverEventSource<V>, Sty
return showItem(ShowItem.of(item, count, nbt));
}

/**
* Creates a hover event that shows an item on hover.
*
* @param item the item
* @param count the count
* @param nbt the nbt
* @return a hover event
* @since 4.6.0
*/
public static @NonNull HoverEvent<ShowItem> showItem(final @NonNull Keyed item, final @NonNegative int count, final @Nullable BinaryTagHolder nbt) {
return showItem(ShowItem.of(item, count, nbt));
}

/**
* Creates a hover event that shows an item on hover.
*
Expand All @@ -115,6 +141,8 @@ public final class HoverEvent<V> implements Examinable, HoverEventSource<V>, Sty
/**
* Creates a hover event that show information about an entity on hover.
*
* <p>In the official <em>Minecraft: Java Edition</em> client, no information will be shown unless the "Advanced tooltips" debug option is enabled.</p>
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
Expand All @@ -127,6 +155,22 @@ public final class HoverEvent<V> implements Examinable, HoverEventSource<V>, Sty
/**
* Creates a hover event that show information about an entity on hover.
*
* <p>In the official <em>Minecraft: Java Edition</em> client, no information will be shown unless the "Advanced tooltips" debug option is enabled.</p>
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
* @since 4.6.0
*/
public static @NonNull HoverEvent<ShowEntity> showEntity(final @NonNull Keyed type, final @NonNull UUID id) {
return showEntity(type, id, null);
}

/**
* Creates a hover event that show information about an entity on hover.
*
* <p>In the official <em>Minecraft: Java Edition</em> client, no information will be shown unless the "Advanced tooltips" debug option is enabled.</p>
*
* @param type the type
* @param id the id
* @param name the name
Expand All @@ -140,6 +184,23 @@ public final class HoverEvent<V> implements Examinable, HoverEventSource<V>, Sty
/**
* Creates a hover event that show information about an entity on hover.
*
* <p>In the official <em>Minecraft: Java Edition</em> client, no information will be shown unless the "Advanced tooltips" debug option is enabled.</p>
*
* @param type the type
* @param id the id
* @param name the name
* @return a {@code ShowEntity}
* @since 4.6.0
*/
public static @NonNull HoverEvent<ShowEntity> showEntity(final @NonNull Keyed type, final @NonNull UUID id, final @Nullable Component name) {
return showEntity(ShowEntity.of(type, id, name));
}

/**
* Creates a hover event that show information about an entity on hover.
*
* <p>In the official <em>Minecraft: Java Edition</em> client, no information will be shown unless the "Advanced tooltips" debug option is enabled.</p>
*
* @param entity the entity to show on hover
* @return a hover event
* @since 4.0.0
Expand Down Expand Up @@ -282,6 +343,18 @@ public static final class ShowItem implements Examinable {
return of(item, count, null);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @return a {@code ShowItem}
* @since 4.6.0
*/
public static @NonNull ShowItem of(final @NonNull Keyed item, final @NonNegative int count) {
return of(item, count, null);
}

/**
* Creates.
*
Expand All @@ -295,6 +368,19 @@ public static final class ShowItem implements Examinable {
return new ShowItem(requireNonNull(item, "item"), count, nbt);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.6.0
*/
public static @NonNull ShowItem of(final @NonNull Keyed item, final @NonNegative int count, final @Nullable BinaryTagHolder nbt) {
return new ShowItem(requireNonNull(item, "item").key(), count, nbt);
}

private ShowItem(final @NonNull Key item, final @NonNegative int count, final @Nullable BinaryTagHolder nbt) {
this.item = item;
this.count = count;
Expand Down Expand Up @@ -420,6 +506,18 @@ public static final class ShowEntity implements Examinable {
return of(type, id, null);
}

/**
* Creates.
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
* @since 4.6.0
*/
public static @NonNull ShowEntity of(final @NonNull Keyed type, final @NonNull UUID id) {
return of(type, id, null);
}

/**
* Creates.
*
Expand All @@ -433,6 +531,19 @@ public static final class ShowEntity implements Examinable {
return new ShowEntity(requireNonNull(type, "type"), requireNonNull(id, "id"), name);
}

/**
* Creates.
*
* @param type the type
* @param id the id
* @param name the name
* @return a {@code ShowEntity}
* @since 4.6.0
*/
public static @NonNull ShowEntity of(final @NonNull Keyed type, final @NonNull UUID id, final @Nullable Component name) {
return new ShowEntity(requireNonNull(type, "type").key(), requireNonNull(id, "id"), name);
}

private ShowEntity(final @NonNull Key type, final @NonNull UUID id, final @Nullable Component name) {
this.type = type;
this.id = id;
Expand Down Expand Up @@ -461,6 +572,17 @@ private ShowEntity(final @NonNull Key type, final @NonNull UUID id, final @Nulla
return new ShowEntity(type, this.id, this.name);
}

/**
* Sets the type.
*
* @param type the type
* @return a {@code ShowEntity}
* @since 4.6.0
*/
public @NonNull ShowEntity type(final @NonNull Keyed type) {
return this.type(requireNonNull(type, "type").key());
}

/**
* Gets the id.
*
Expand Down

0 comments on commit 5ffdd94

Please sign in to comment.