Skip to content

Commit

Permalink
javadocs, rearrange a bit, visibilty
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Nov 2, 2024
1 parent 73bd2b4 commit f594e19
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.bukkit.Location;
import org.bukkit.block.Block;
Expand All @@ -21,6 +20,20 @@
* @see HologramsService
*/
public interface HologramOwner extends ItemAttribute {
/**
* This returns the offset of the hologram as a {@link Vector}.
* This offset is applied to {@link Block#getLocation()} when spawning
* the hologram.
*
* @param block
* The {@link Block} which serves as the origin point
*
* @return The hologram offset
*/
@Nonnull
default Vector getHologramOffset(@Nonnull Block block) {
return Slimefun.getHologramsService().getDefaultOffset();
}

/**
* This will update the hologram text for the given {@link Block}.
Expand All @@ -31,17 +44,32 @@ public interface HologramOwner extends ItemAttribute {
* @param text
* The text for the hologram
*/
default void updateHologram(@Nonnull Block block, @Nullable String text) {
Location location = block.getLocation().add(getHologramOffset(block));
if (text != null) {
text = ChatColors.color(text);
default void updateHologram(@Nonnull Block block, @Nonnull String text) {
Location location = block.getLocation();
if (Slimefun.getTickerTask().isDeletedSoon(location)) {
return;
}
Slimefun.getHologramsService().setHologramLabel(location, text);

Slimefun.getHologramsService().setHologramLabel(location.add(getHologramOffset(block)), ChatColors.color(text));
}

default void setOffset(@Nonnull Block block, Vector offset) {
Location hologramLocation = block.getLocation().add(getHologramOffset(block));
Location newHologramLocation = block.getLocation().add(offset);
/**
* This will update the hologram text for the given {@link Block}.
*
* @param block
* The {@link Block} to which the hologram belongs
*
* @param offset
* The new offset for the hologram
*/
default void setOffset(@Nonnull Block block, @Nonnull Vector offset) {
Location location = block.getLocation();
if (Slimefun.getTickerTask().isDeletedSoon(location)) {
return;
}

Location hologramLocation = location.clone().add(getHologramOffset(block));
Location newHologramLocation = location.clone().add(offset);
Slimefun.getHologramsService().teleportHologram(hologramLocation, newHologramLocation);
}

Expand All @@ -55,20 +83,4 @@ default void removeHologram(@Nonnull Block block) {
Location location = block.getLocation().add(getHologramOffset(block));
Slimefun.getHologramsService().removeHologram(location);
}

/**
* This returns the offset of the hologram as a {@link Vector}.
* This offset is applied to {@link Block#getLocation()} when spawning
* the hologram.
*
* @param block
* The {@link Block} which serves as the origin point
*
* @return The hologram offset
*/
@Nonnull
default Vector getHologramOffset(@Nonnull Block block) {
return Slimefun.getHologramsService().getDefaultOffset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Objects;

public class ArmorStandHologram extends Hologram<ArmorStand> {

private ArmorStandHologram(ArmorStand entity) {
super(entity.getUniqueId());
}
Expand All @@ -35,7 +34,7 @@ public Class<ArmorStand> getEntityType() {
return ArmorStand.class;
}

public static Hologram<?> of(Entity entity, BlockPosition position) {
static ArmorStandHologram of(Entity entity, BlockPosition position) {
if (!(entity instanceof ArmorStand armorStand)) {
return null;
}
Expand All @@ -47,9 +46,8 @@ public static Hologram<?> of(Entity entity, BlockPosition position) {
return new ArmorStandHologram(armorStand);
}

public static Hologram<?> create(Location location, BlockPosition position) {
static ArmorStandHologram create(Location location, BlockPosition position) {
ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class);
return of(armorStand, position);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author TheBusyBiscuit, JustAHuman
*/
public abstract class Hologram<E extends Entity> {
abstract class Hologram<E extends Entity> {
private static final long EXPIRES_AFTER = TimeUnit.MINUTES.toMillis(10);

protected final UUID uniqueId;
Expand Down Expand Up @@ -92,5 +92,4 @@ public void remove() {
entity.remove();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,42 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer<Hologram<?>
}
}

/**
* This will update the text of the {@link Hologram}.
*
* @param location
* The {@link Location} of this {@link Hologram}
* @param text
* The text to set, can be null
*/
public void setHologramLabel(@Nonnull Location location, @Nullable String text) {
Validate.notNull(location, "Location must not be null");

updateHologram(location, hologram -> hologram.setText(text));
}

/**
* This will teleport the {@link Hologram} to the given {@link Location}.
*
* @param location
* The {@link Location} of this {@link Hologram}
* @param to
* The {@link Location} to teleport the {@link Hologram} to
*/
public void teleportHologram(@Nonnull Location location, @Nonnull Location to) {
Validate.notNull(location, "Location must not be null");

updateHologram(location, hologram -> hologram.teleport(to));
}

/**
* This removes the {@link Hologram} at that given {@link Location}.
* <p>
* <strong>This method must be executed on the main {@link Server} {@link Thread}.</strong>
*
*
* @param location
* The {@link Location}
*
*
* @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not
* exist or was already removed
*/
Expand All @@ -239,25 +267,4 @@ public boolean removeHologram(@Nonnull Location location) {
return false;
}
}

/**
* This will update the text of the {@link Hologram}.
*
* @param location
* The {@link Location} of this {@link Hologram}
* @param text
* The text to set, can be null
*/
public void setHologramLabel(@Nonnull Location location, @Nullable String text) {
Validate.notNull(location, "Location must not be null");

updateHologram(location, hologram -> hologram.setText(text));
}

public void teleportHologram(@Nonnull Location location, @Nonnull Location to) {
Validate.notNull(location, "Location must not be null");

updateHologram(location, hologram -> hologram.teleport(to));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Objects;

public class TextDisplayHologram extends Hologram<TextDisplay> {

private TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
super(textDisplay.getUniqueId());
}
Expand All @@ -35,7 +34,7 @@ public Class<TextDisplay> getEntityType() {
return TextDisplay.class;
}

public static TextDisplayHologram of(Entity entity, BlockPosition position) {
static TextDisplayHologram of(Entity entity, BlockPosition position) {
if (!(entity instanceof TextDisplay textDisplay)) {
return null;
}
Expand All @@ -44,9 +43,8 @@ public static TextDisplayHologram of(Entity entity, BlockPosition position) {
return new TextDisplayHologram(textDisplay);
}

public static TextDisplayHologram create(Location location, BlockPosition position) {
static TextDisplayHologram create(Location location, BlockPosition position) {
TextDisplay textDisplay = location.getWorld().spawn(location, TextDisplay.class);
return of(textDisplay, position);
}

}

0 comments on commit f594e19

Please sign in to comment.