Skip to content

Commit

Permalink
Merge pull request #923 from powercasgamer/chore/rename-static
Browse files Browse the repository at this point in the history
chore: rename static constructors
  • Loading branch information
zml2008 authored May 12, 2023
2 parents c6fb10f + ac6a367 commit 7073ec3
Show file tree
Hide file tree
Showing 36 changed files with 498 additions and 183 deletions.
125 changes: 125 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 @@ -39,6 +39,7 @@
import net.kyori.adventure.util.Index;
import net.kyori.examination.Examinable;
import net.kyori.examination.ExaminableProperty;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
Expand Down Expand Up @@ -331,30 +332,73 @@ public static final class ShowItem implements Examinable {
private final int count;
private final @Nullable BinaryTagHolder nbt;

/**
* Creates.
*
* @param item the item
* @param count the count
* @return a {@code ShowItem}
* @since 4.14.0
*/
public static @NotNull ShowItem showItem(final @NotNull Key item, final @Range(from = 0, to = Integer.MAX_VALUE) int count) {
return showItem(item, count, null);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @return a {@code ShowItem}
* @since 4.0.0
* @deprecated for removal since 4.14.0, use {@link #showItem(Key, int)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowItem of(final @NotNull Key item, final @Range(from = 0, to = Integer.MAX_VALUE) int count) {
return of(item, count, null);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @return a {@code ShowItem}
* @since 4.14.0
*/
public static @NotNull ShowItem showItem(final @NotNull Keyed item, final @Range(from = 0, to = Integer.MAX_VALUE) int count) {
return showItem(item, count, null);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @return a {@code ShowItem}
* @since 4.6.0
* @deprecated for removal since 4.14.0, use {@link #showItem(Keyed, int)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowItem of(final @NotNull Keyed item, final @Range(from = 0, to = Integer.MAX_VALUE) int count) {
return of(item, count, null);
}

/**
* Creates.
*
* @param item the item
* @param count the count
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.14.0
*/
public static @NotNull ShowItem showItem(final @NotNull Key item, final @Range(from = 0, to = Integer.MAX_VALUE) int count, final @Nullable BinaryTagHolder nbt) {
return new ShowItem(requireNonNull(item, "item"), count, nbt);
}

/**
* Creates.
*
Expand All @@ -363,11 +407,27 @@ public static final class ShowItem implements Examinable {
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.0.0
* @deprecated for removal since 4.14.0, use {@link #showItem(Key, int, BinaryTagHolder)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowItem of(final @NotNull Key item, final @Range(from = 0, to = Integer.MAX_VALUE) int count, final @Nullable BinaryTagHolder nbt) {
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.14.0
*/
public static @NotNull ShowItem showItem(final @NotNull Keyed item, final @Range(from = 0, to = Integer.MAX_VALUE) int count, final @Nullable BinaryTagHolder nbt) {
return new ShowItem(requireNonNull(item, "item").key(), count, nbt);
}

/**
* Creates.
*
Expand All @@ -376,7 +436,10 @@ public static final class ShowItem implements Examinable {
* @param nbt the nbt
* @return a {@code ShowItem}
* @since 4.6.0
* @deprecated for removal since 4.14.0, use {@link #showItem(Keyed, int, BinaryTagHolder)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowItem of(final @NotNull Keyed item, final @Range(from = 0, to = Integer.MAX_VALUE) int count, final @Nullable BinaryTagHolder nbt) {
return new ShowItem(requireNonNull(item, "item").key(), count, nbt);
}
Expand Down Expand Up @@ -494,30 +557,73 @@ public static final class ShowEntity implements Examinable {
private final UUID id;
private final Component name;

/**
* Creates.
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
* @since 4.14.0
*/
public static @NotNull ShowEntity showEntity(final @NotNull Key type, final @NotNull UUID id) {
return showEntity(type, id, null);
}

/**
* Creates.
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
* @since 4.0.0
* @deprecated for removal since 4.14.0, use {@link #showEntity(Key, UUID)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowEntity of(final @NotNull Key type, final @NotNull UUID id) {
return of(type, id, null);
}

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

/**
* Creates.
*
* @param type the type
* @param id the id
* @return a {@code ShowEntity}
* @since 4.6.0
* @deprecated for removal since 4.14.0, use {@link #showEntity(Keyed, UUID)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowEntity of(final @NotNull Keyed type, final @NotNull UUID id) {
return of(type, id, null);
}

/**
* Creates.
*
* @param type the type
* @param id the id
* @param name the name
* @return a {@code ShowEntity}
* @since 4.14.0
*/
public static @NotNull ShowEntity showEntity(final @NotNull Key type, final @NotNull UUID id, final @Nullable Component name) {
return new ShowEntity(requireNonNull(type, "type"), requireNonNull(id, "id"), name);
}

/**
* Creates.
*
Expand All @@ -526,11 +632,27 @@ public static final class ShowEntity implements Examinable {
* @param name the name
* @return a {@code ShowEntity}
* @since 4.0.0
* @deprecated for removal since 4.14.0, use {@link #showEntity(Key, UUID, Component)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowEntity of(final @NotNull Key type, final @NotNull UUID id, final @Nullable Component name) {
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.14.0
*/
public static @NotNull ShowEntity showEntity(final @NotNull Keyed type, final @NotNull UUID id, final @Nullable Component name) {
return new ShowEntity(requireNonNull(type, "type").key(), requireNonNull(id, "id"), name);
}

/**
* Creates.
*
Expand All @@ -539,7 +661,10 @@ public static final class ShowEntity implements Examinable {
* @param name the name
* @return a {@code ShowEntity}
* @since 4.6.0
* @deprecated for removal since 4.14.0, use {@link #showEntity(Keyed, UUID, Component)} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
public static @NotNull ShowEntity of(final @NotNull Keyed type, final @NotNull UUID id, final @Nullable Component name) {
return new ShowEntity(requireNonNull(type, "type").key(), requireNonNull(id, "id"), name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void testAsHoverEvent() {

@Test
void testShowItemItem() {
final HoverEvent.ShowItem si0 = HoverEvent.ShowItem.of(Key.key("stone"), 1);
final HoverEvent.ShowItem si0 = HoverEvent.ShowItem.showItem(Key.key("stone"), 1);
assertEquals(Key.key("stone"), si0.item());
final HoverEvent.ShowItem si1 = si0.item(Key.key("dirt"));
assertEquals(Key.key("stone"), si0.item()); // original should be unmodified
Expand All @@ -55,7 +55,7 @@ void testShowItemItem() {

@Test
void testShowItemCount() {
final HoverEvent.ShowItem si0 = HoverEvent.ShowItem.of(Key.key("stone"), 1);
final HoverEvent.ShowItem si0 = HoverEvent.ShowItem.showItem(Key.key("stone"), 1);
assertEquals(1, si0.count());
assertSame(si0, si0.count(1)); // unmodified
final HoverEvent.ShowItem si1 = si0.count(2);
Expand All @@ -65,7 +65,7 @@ void testShowItemCount() {

@Test
void testShowEntityType() {
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.of(Key.key("cow"), UUID.randomUUID());
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.showEntity(Key.key("cow"), UUID.randomUUID());
assertEquals(Key.key("cow"), se0.type());
final HoverEvent.ShowEntity se1 = se0.type(Key.key("chicken"));
assertEquals(Key.key("cow"), se0.type()); // original should be unmodified
Expand All @@ -75,7 +75,7 @@ void testShowEntityType() {
@Test
void testShowEntityId() {
final UUID id0 = UUID.randomUUID();
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.of(Key.key("cow"), id0);
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.showEntity(Key.key("cow"), id0);
assertEquals(id0, se0.id());
final UUID id1 = UUID.randomUUID();
final HoverEvent.ShowEntity se1 = se0.id(id1);
Expand All @@ -86,7 +86,7 @@ void testShowEntityId() {
@Test
void testShowEntityName() {
final Component n0 = Component.text("Cow");
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.of(Key.key("cow"), UUID.randomUUID(), n0);
final HoverEvent.ShowEntity se0 = HoverEvent.ShowEntity.showEntity(Key.key("cow"), UUID.randomUUID(), n0);
assertEquals(n0, se0.name());
final Component n1 = Component.text("Chicken");
final HoverEvent.ShowEntity se1 = se0.name(n1);
Expand All @@ -104,19 +104,19 @@ void testEquality() {
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, Component.empty())
)
.addEqualityGroup(
HoverEvent.showItem(HoverEvent.ShowItem.of(Key.key("air"), 1, null)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ShowItem.of(Key.key("air"), 1, null))
HoverEvent.showItem(HoverEvent.ShowItem.showItem(Key.key("air"), 1, null)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ShowItem.showItem(Key.key("air"), 1, null))
)
.addEqualityGroup(
HoverEvent.showEntity(HoverEvent.ShowEntity.of(Key.key("cat"), entity)),
HoverEvent.showEntity(HoverEvent.ShowEntity.of(Key.key("cat"), entity, null)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.of(Key.key("cat"), entity)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.of(Key.key("cat"), entity, null)),
HoverEvent.showEntity(HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity)),
HoverEvent.showEntity(HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity, null)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity)),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity, null)),
HoverEvent.showEntity(Key.key("cat"), entity, null)
)
.addEqualityGroup(
HoverEvent.showEntity(HoverEvent.ShowEntity.of(Key.key("cat"), entity, Component.empty())),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.of(Key.key("cat"), entity, Component.empty())),
HoverEvent.showEntity(HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity, Component.empty())),
HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ENTITY, HoverEvent.ShowEntity.showEntity(Key.key("cat"), entity, Component.empty())),
HoverEvent.showEntity(Key.key("cat"), entity, Component.empty())
)
.testEquals();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class BinaryTagReaderImpl implements BinaryTagIO.Reader {
input = new TrackingDataInput(input, this.maxBytes);
}

final BinaryTagType<? extends BinaryTag> type = BinaryTagType.of(input.readByte());
final BinaryTagType<? extends BinaryTag> type = BinaryTagType.binaryTagType(input.readByte());
requireCompound(type);
input.skipBytes(input.readUnsignedShort()); // read empty name
return BinaryTagTypes.COMPOUND.read(input);
Expand All @@ -88,7 +88,7 @@ final class BinaryTagReaderImpl implements BinaryTagIO.Reader {

@Override
public Map.@NotNull Entry<String, CompoundBinaryTag> readNamed(final @NotNull DataInput input) throws IOException {
final BinaryTagType<? extends BinaryTag> type = BinaryTagType.of(input.readByte());
final BinaryTagType<? extends BinaryTag> type = BinaryTagType.binaryTagType(input.readByte());
requireCompound(type);
final String name = input.readUTF();
return new AbstractMap.SimpleImmutableEntry<>(name, BinaryTagTypes.COMPOUND.read(input));
Expand Down
9 changes: 8 additions & 1 deletion nbt/src/main/java/net/kyori/adventure/nbt/BinaryTagType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -76,7 +77,7 @@ static <T extends BinaryTag> void writeUntyped(final BinaryTagType<? extends Bin
((BinaryTagType<T>) type).write(tag, output);
}

static @NotNull BinaryTagType<? extends BinaryTag> of(final byte id) {
static @NotNull BinaryTagType<? extends BinaryTag> binaryTagType(final byte id) {
for (int i = 0; i < TYPES.size(); i++) {
final BinaryTagType<? extends BinaryTag> type = TYPES.get(i);
if (type.id() == id) {
Expand All @@ -86,6 +87,12 @@ static <T extends BinaryTag> void writeUntyped(final BinaryTagType<? extends Bin
throw new IllegalArgumentException(String.valueOf(id));
}

@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "5.0.0")
static @NotNull BinaryTagType<? extends BinaryTag> of(final byte id) {
return binaryTagType(id);
}

static <T extends BinaryTag> @NotNull BinaryTagType<T> register(final Class<T> type, final byte id, final Reader<T> reader, final @Nullable Writer<T> writer) {
return register(new Impl<>(type, id, reader, writer));
}
Expand Down
Loading

0 comments on commit 7073ec3

Please sign in to comment.