Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions holoeasy-core/src/main/java/org/holoeasy/hologram/Hologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.function.Function;

public class Hologram {

private final HoloEasy lib;
private final PrivateConfig pvt;
private final UUID id = UUID.randomUUID();
Expand All @@ -37,61 +36,61 @@ public Hologram(@NotNull HoloEasy lib, @NotNull Location location) {
this(lib, location, null, null);
}

public HoloEasy getLib() {
public @NotNull HoloEasy getLib() {
return lib;
}

@ApiStatus.Internal
public PrivateConfig getPvt() {
public @NotNull PrivateConfig getPvt() {
return pvt;
}

public UUID getId() {
public @NotNull UUID getId() {
return id;
}

public Location getLocation() {
public @NotNull Location getLocation() {
return location;
}

public List<Line<?>> getLines() {
public @NotNull List<Line<?>> getLines() {
return lines;
}

protected BlockLine blockLine(@NotNull Function<Player, ItemStack> blockSupplier) {
protected @NotNull BlockLine blockLine(@NotNull Function<@NotNull Player, @NotNull ItemStack> blockSupplier) {
BlockLine line = new BlockLine(this, blockSupplier);
lines.add(line);
return line;
}

protected ItemLine itemLine(@NotNull Function<Player, ItemStack> itemSupplier) {
protected @NotNull ItemLine itemLine(@NotNull Function<@NotNull Player, @NotNull ItemStack> itemSupplier) {
ItemLine line = new ItemLine(this, itemSupplier);
lines.add(line);
return line;
}

protected TextLine textLine(@NotNull Function<Player, String> textSupplier) {
protected @NotNull TextLine textLine(@NotNull Function<@NotNull Player, @NotNull String> textSupplier) {
TextLine line = new TextLine(this, textSupplier);
lines.add(line);
return line;
}

@ApiStatus.Experimental
protected DisplayTextLine displayTextLine(@NotNull Function<Player, String> textSupplier) {
protected @NotNull DisplayTextLine displayTextLine(@NotNull Function<@NotNull Player, @NotNull String> textSupplier) {
DisplayTextLine line = new DisplayTextLine(this, textSupplier);
lines.add(line);
return line;
}

@ApiStatus.Experimental
protected DisplayBlockLine displayBlockLine(@NotNull Function<Player, Material> materialSupplier) {
protected @NotNull DisplayBlockLine displayBlockLine(@NotNull Function<@NotNull Player, @NotNull Material> materialSupplier) {
DisplayBlockLine line = new DisplayBlockLine(this, materialSupplier);
lines.add(line);
return line;
}

@ApiStatus.Experimental
protected InteractionLine interactionLine() {
protected @NotNull InteractionLine interactionLine() {
InteractionLine line = new InteractionLine(this);
lines.add(line);
return line;
Expand All @@ -117,18 +116,18 @@ public void teleport(@NotNull Location to) {
}
}

public boolean isShownFor(Player player) {
public boolean isShownFor(@NotNull Player player) {
return pvt.getSeeingPlayers().contains(player);
}

public <T extends Hologram> void show(IHologramPool<T> pool) {
public <T extends Hologram> void show(@NotNull IHologramPool<T> pool) {
if (pool.getHolograms().stream().anyMatch(h -> h.getId().equals(this.id))) {
throw new KeyAlreadyExistsException(this.id);
}
pool.getHolograms().add((T) this);
}

public void show(Player player) {
public void show(@NotNull Player player) {
if (!loaded) {
if(lines.isEmpty()) {
throw new IllegalStateException("Cannot show hologram with no lines.");
Expand All @@ -147,7 +146,7 @@ public void show(Player player) {
}
}

public void hide(Player player) {
public void hide(@NotNull Player player) {
for (Line<?> line : lines) {
(line).hide(player);
}
Expand All @@ -158,7 +157,7 @@ public void hide(Player player) {
}
}

public void hide(IHologramPool<?> pool) {
public void hide(@NotNull IHologramPool<?> pool) {
boolean removed = pool.getHolograms().remove(this);
if (removed) {
for (Player player : pvt.getSeeingPlayers()) {
Expand All @@ -167,6 +166,33 @@ public void hide(IHologramPool<?> pool) {
}
}

public void updateLines() {
for (Line<?> line : lines) {
line.updateAll();
}
}

public void replaceLines(@NotNull List<? extends Line<?>> newLines) {
// hide current lines from all players
for (Player player : pvt.getSeeingPlayers()) {
for (Line<?> line : lines) {
line.hide(player);
}
}

lines.clear();
loaded = false;
lines.addAll(newLines);
pvt.updateLinesLocation();
Comment thread
denmeh marked this conversation as resolved.

// show new lines to all players
for (Player player : pvt.getSeeingPlayers()) {
for (Line<?> line : lines) {
line.show(player);
}
}
}
Comment thread
denmeh marked this conversation as resolved.

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down