Skip to content

Commit

Permalink
use ComponentLike instead of Component in API method arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vytskalt committed Mar 6, 2024
1 parent 0f2f3ba commit e957539
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.noop;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
Expand All @@ -25,8 +26,8 @@ public class NoopScoreboardObjective implements ScoreboardObjective {
}

@Override
public @NotNull ScoreboardObjective value(@NotNull Component value) {
this.value = value;
public @NotNull ScoreboardObjective value(@NotNull ComponentLike value) {
this.value = value.asComponent();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -67,10 +68,10 @@ public boolean removePlayer(@NotNull Player player) {
}

@Override
public void line(int index, @Nullable Component value, @Nullable ScoreFormat scoreFormat) {
public void line(int index, @Nullable ComponentLike value, @Nullable ScoreFormat scoreFormat) {
checkLineBounds(index);
checkClosed();
lines[index] = value;
lines[index] = value == null ? null : value.asComponent();
}

@Override
Expand All @@ -86,10 +87,10 @@ public void line(int index, @Nullable Component value, @Nullable ScoreFormat sco
}

@Override
public void title(@NotNull Component title) {
public void title(@NotNull ComponentLike title) {
Preconditions.checkNotNull(title);
checkClosed();
this.title = title;
this.title = title.asComponent();
}

private void checkClosed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.noop;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.format.NamedTextColor;
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
import net.megavex.scoreboardlibrary.api.team.TeamDisplay;
Expand Down Expand Up @@ -58,8 +59,8 @@ public boolean removeEntry(@NotNull String entry) {
}

@Override
public @NotNull TeamDisplay displayName(@NotNull Component displayName) {
this.displayName = displayName;
public @NotNull TeamDisplay displayName(@NotNull ComponentLike displayName) {
this.displayName = displayName.asComponent();
return this;
}

Expand All @@ -69,8 +70,8 @@ public boolean removeEntry(@NotNull String entry) {
}

@Override
public @NotNull TeamDisplay prefix(@NotNull Component prefix) {
this.prefix = prefix;
public @NotNull TeamDisplay prefix(@NotNull ComponentLike prefix) {
this.prefix = prefix.asComponent();
return this;
}

Expand All @@ -80,8 +81,8 @@ public boolean removeEntry(@NotNull String entry) {
}

@Override
public @NotNull TeamDisplay suffix(@NotNull Component suffix) {
this.suffix = suffix;
public @NotNull TeamDisplay suffix(@NotNull ComponentLike suffix) {
this.suffix = suffix.asComponent();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.objective;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand All @@ -13,9 +14,9 @@ public final class ObjectiveScore {
private final Component displayName;
private final ScoreFormat format;

public ObjectiveScore(int value, @Nullable Component displayName, @Nullable ScoreFormat format) {
public ObjectiveScore(int value, @Nullable ComponentLike displayName, @Nullable ScoreFormat format) {
this.value = value;
this.displayName = displayName;
this.displayName = displayName == null ? null : displayName.asComponent();
this.format = format;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.objective;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -21,7 +22,7 @@ public interface ScoreboardObjective {
*
* @param value New value
*/
@NotNull ScoreboardObjective value(@NotNull Component value);
@NotNull ScoreboardObjective value(@NotNull ComponentLike value);

/**
* @return The render type of the objective, defaults to {@link ObjectiveRenderType#INTEGER}
Expand Down Expand Up @@ -98,7 +99,7 @@ public interface ScoreboardObjective {
default @NotNull ScoreboardObjective score(
@NotNull String entry,
int scoreValue,
@Nullable Component displayName,
@Nullable ComponentLike displayName,
@Nullable ScoreFormat scoreFormat
) {
return score(entry, new ObjectiveScore(scoreValue, displayName, scoreFormat));
Expand All @@ -114,7 +115,7 @@ public interface ScoreboardObjective {
default @NotNull ScoreboardObjective score(
@NotNull String entry,
int scoreValue,
@Nullable Component displayName
@Nullable ComponentLike displayName
) {
return score(entry, new ObjectiveScore(scoreValue, displayName, null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.sidebar;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -55,7 +56,7 @@ public interface Sidebar {
* @param index Line index
* @param value New value, or null to hide
*/
default void line(@Range(from = 0, to = Integer.MAX_VALUE - 1) int index, @Nullable Component value) {
default void line(@Range(from = 0, to = Integer.MAX_VALUE - 1) int index, @Nullable ComponentLike value) {
line(index, value, null);
}

Expand All @@ -69,7 +70,7 @@ default void line(@Range(from = 0, to = Integer.MAX_VALUE - 1) int index, @Nulla
*/
void line(
@Range(from = 0, to = Integer.MAX_VALUE - 1) int index,
@Nullable Component value,
@Nullable ComponentLike value,
@Nullable ScoreFormat scoreFormat
);

Expand All @@ -94,7 +95,7 @@ default void clearLines() {
*
* @param title Title
*/
void title(@NotNull Component title);
void title(@NotNull ComponentLike title);

// Players

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -47,11 +48,11 @@ private static class SidebarTitleDrawable implements LineDrawable {
private Component title;

@Override
public void drawLine(@NotNull Component line, @Nullable ScoreFormat scoreFormat) {
public void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat) {
Preconditions.checkNotNull(line);

if (title == null) {
title = line;
title = line.asComponent();
}
}
}
Expand All @@ -65,7 +66,7 @@ public SidebarLineDrawable(@NotNull Sidebar sidebar) {
}

@Override
public void drawLine(@NotNull Component line, @Nullable ScoreFormat scoreFormat) {
public void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat) {
Preconditions.checkNotNull(line);

if (index < Sidebar.MAX_LINES) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.megavex.scoreboardlibrary.api.sidebar.component;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -16,7 +16,7 @@ public interface LineDrawable {
*
* @param line line component
*/
default void drawLine(@NotNull Component line) {
default void drawLine(@NotNull ComponentLike line) {
drawLine(line, null);
}

Expand All @@ -26,5 +26,5 @@ default void drawLine(@NotNull Component line) {
* @param line line component
* @param scoreFormat score format
*/
void drawLine(@NotNull Component line, @Nullable ScoreFormat scoreFormat);
void drawLine(@NotNull ComponentLike line, @Nullable ScoreFormat scoreFormat);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,12 +14,12 @@
import static net.kyori.adventure.text.Component.empty;

public interface SidebarComponent {
static @NotNull SidebarComponent staticLine(@NotNull Component line) {
static @NotNull SidebarComponent staticLine(@NotNull ComponentLike line) {
Preconditions.checkNotNull(line);
return drawable -> drawable.drawLine(line);
}

static @NotNull SidebarComponent staticLine(@NotNull Component line, @NotNull ScoreFormat scoreFormat) {
static @NotNull SidebarComponent staticLine(@NotNull ComponentLike line, @NotNull ScoreFormat scoreFormat) {
Preconditions.checkNotNull(line);
return drawable -> drawable.drawLine(line, scoreFormat);
}
Expand All @@ -28,16 +28,16 @@ public interface SidebarComponent {
return drawable -> drawable.drawLine(empty());
}

static @NotNull SidebarComponent dynamicLine(@NotNull Supplier<Component> lineSupplier) {
static @NotNull <T extends ComponentLike> SidebarComponent dynamicLine(@NotNull Supplier<T> lineSupplier) {
return drawable -> drawable.drawLine(lineSupplier.get());
}

static @NotNull SidebarComponent animatedLine(@NotNull SidebarAnimation<Component> animation) {
static @NotNull <T extends ComponentLike> SidebarComponent animatedLine(@NotNull SidebarAnimation<T> animation) {
Preconditions.checkNotNull(animation);
return drawable -> drawable.drawLine(animation.currentFrame());
}

static @NotNull SidebarComponent animatedComponent(@NotNull SidebarAnimation<SidebarComponent> animation) {
static @NotNull <T extends SidebarComponent> SidebarComponent animatedComponent(@NotNull SidebarAnimation<T> animation) {
Preconditions.checkNotNull(animation);
return drawable -> animation.currentFrame().draw(drawable);
}
Expand All @@ -60,27 +60,27 @@ private Builder() {
return this;
}

public @NotNull Builder addStaticLine(@NotNull Component line) {
public @NotNull Builder addStaticLine(@NotNull ComponentLike line) {
return addComponent(SidebarComponent.staticLine(line));
}

public @NotNull Builder addStaticLine(@NotNull Component line, @NotNull ScoreFormat scoreFormat) {
public @NotNull Builder addStaticLine(@NotNull ComponentLike line, @NotNull ScoreFormat scoreFormat) {
return addComponent(SidebarComponent.staticLine(line, scoreFormat));
}

public @NotNull Builder addBlankLine() {
return addComponent(SidebarComponent.blankLine());
}

public @NotNull Builder addDynamicLine(@NotNull Supplier<Component> lineSupplier) {
public @NotNull <T extends ComponentLike> Builder addDynamicLine(@NotNull Supplier<T> lineSupplier) {
return addComponent(SidebarComponent.dynamicLine(lineSupplier));
}

public @NotNull Builder addAnimatedLine(@NotNull SidebarAnimation<Component> animation) {
public <T extends ComponentLike> @NotNull Builder addAnimatedLine(@NotNull SidebarAnimation<T> animation) {
return addComponent(SidebarComponent.animatedLine(animation));
}

public @NotNull Builder addAnimatedComponent(@NotNull SidebarAnimation<SidebarComponent> animation) {
public @NotNull <T extends SidebarComponent> Builder addAnimatedComponent(@NotNull SidebarAnimation<T> animation) {
return addComponent(SidebarComponent.animatedComponent(animation));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.api.team;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.format.NamedTextColor;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
import net.megavex.scoreboardlibrary.api.team.enums.CollisionRule;
Expand Down Expand Up @@ -62,7 +63,7 @@ public interface TeamDisplay {
*
* @param displayName new display name
*/
@NotNull TeamDisplay displayName(@NotNull Component displayName);
@NotNull TeamDisplay displayName(@NotNull ComponentLike displayName);

/**
* Gets the prefix, which defaults to {@link Component#empty()}.
Expand All @@ -78,7 +79,7 @@ public interface TeamDisplay {
* @param prefix new prefix
* @see #prefix()
*/
@NotNull TeamDisplay prefix(@NotNull Component prefix);
@NotNull TeamDisplay prefix(@NotNull ComponentLike prefix);

/**
* Gets the suffix, which defaults to {@link Component#empty()}.
Expand All @@ -94,7 +95,7 @@ public interface TeamDisplay {
* @param suffix new suffix
* @see #suffix()
*/
@NotNull TeamDisplay suffix(@NotNull Component suffix);
@NotNull TeamDisplay suffix(@NotNull ComponentLike suffix);

/**
* @return friendly fire rule value, defaults to false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.megavex.scoreboardlibrary.implementation.objective;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveScore;
import net.megavex.scoreboardlibrary.api.objective.ScoreFormat;
Expand Down Expand Up @@ -54,9 +55,10 @@ public void close() {
}

@Override
public @NotNull ScoreboardObjective value(@NotNull Component value) {
if (!this.value.equals(value)) {
this.value = value;
public @NotNull ScoreboardObjective value(@NotNull ComponentLike value) {
Component component = value.asComponent();
if (!this.value.equals(component)) {
this.value = component;
if (!closed) {
taskQueue.add(new ObjectiveManagerTask.UpdateObjective(this));
}
Expand Down
Loading

0 comments on commit e957539

Please sign in to comment.