Skip to content

Commit

Permalink
update FancyHologram implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Feb 25, 2024
1 parent 2fea137 commit 4b478f9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public interface DisplayHologram<T> extends Hologram<T> {
*
* @return the scale
*/
float getScale();
DisplayScale getScale();

/**
* Set the scale of the text
*
* @param scale the scale
*/
void setScale(float scale);
void setScale(DisplayScale scale);

/**
* Get the shadow radius
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.hsgamer.unihologram.display;

/**
* The scale of the hologram
*/
public class DisplayScale {
/**
* The scale in the x-axis
*/
public final float x;
/**
* The scale in the y-axis
*/
public final float y;
/**
* The scale in the z-axis
*/
public final float z;

/**
* Create a new scale
*
* @param x the scale in the x-axis
* @param y the scale in the y-axis
* @param z the scale in the z-axis
*/
public DisplayScale(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package me.hsgamer.unihologram.spigot.fancyholograms.hologram;

import com.google.common.base.Preconditions;
import de.oliver.fancyholograms.FancyHologramsPlugin;
import de.oliver.fancyholograms.HologramManagerImpl;
import de.oliver.fancyholograms.api.FancyHologramsPlugin;
import de.oliver.fancyholograms.api.Hologram;
import de.oliver.fancyholograms.api.HologramData;
import me.hsgamer.unihologram.common.api.HologramLine;
import me.hsgamer.unihologram.common.line.TextHologramLine;
import me.hsgamer.unihologram.display.DisplayBillboard;
import me.hsgamer.unihologram.display.DisplayHologram;
import me.hsgamer.unihologram.display.DisplayScale;
import me.hsgamer.unihologram.display.DisplayTextAlignment;
import me.hsgamer.unihologram.spigot.common.hologram.extra.Colored;
import me.hsgamer.unihologram.spigot.common.hologram.extra.PlayerVisibility;
Expand All @@ -21,6 +23,7 @@
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3f;

import java.awt.*;
import java.util.ArrayList;
Expand All @@ -45,7 +48,7 @@ public class FHHologram implements me.hsgamer.unihologram.common.api.Hologram<Lo
public FHHologram(String name, Location location) {
HologramData data = new HologramData(name);
data.setLocation(location);
this.hologram = FancyHologramsPlugin.get().getHologramsManager().create(data);
this.hologram = FancyHologramsPlugin.get().getHologramManager().create(data);
}

/**
Expand All @@ -63,28 +66,28 @@ private static Location getTopLocation(Location location, float scale, int lineC
return newLocation;
}

private static Location getBottomLocation(Location location, float scale, int lineCount) {
private static Location getBottomLocation(Location location, float yScale, int lineCount) {
Location newLocation = Objects.requireNonNull(location).clone();
newLocation.setY(newLocation.getY() - LINE_HEIGHT * scale * lineCount);
newLocation.setY(newLocation.getY() - LINE_HEIGHT * yScale * lineCount);
return newLocation;
}

private Location getTopLocation() {
return getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale(), hologram.getData().getText().size());
return getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale().y, hologram.getData().getText().size());
}

private void setTopLocation(Location location) {
hologram.getData().setLocation(getBottomLocation(location, hologram.getData().getScale(), hologram.getData().getText().size()));
hologram.getData().setLocation(getBottomLocation(location, hologram.getData().getScale().y, hologram.getData().getText().size()));
}

private void updateTopLocation(float scale, int lineCount) {
Location topLocation = getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale(), hologram.getData().getText().size());
Location bottomLocation = getBottomLocation(topLocation, scale, lineCount);
private void updateTopLocation(float yScale, int lineCount) {
Location topLocation = getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale().y, hologram.getData().getText().size());
Location bottomLocation = getBottomLocation(topLocation, yScale, lineCount);
hologram.getData().setLocation(bottomLocation);
}

private void updateTopLocation(int lineCount) {
updateTopLocation(hologram.getData().getScale(), lineCount);
updateTopLocation(hologram.getData().getScale().y, lineCount);
}

private void checkHologramInitialized() {
Expand All @@ -93,7 +96,7 @@ private void checkHologramInitialized() {

private void updateHologram() {
hologram.updateHologram();
FancyHologramsPlugin.get().getHologramsManager().refreshHologramForPlayersInWorld(hologram);
((HologramManagerImpl) FancyHologramsPlugin.get().getHologramManager()).refreshHologramForPlayersInWorld(hologram);
}

private String toText(HologramLine line) {
Expand Down Expand Up @@ -157,19 +160,19 @@ public String getName() {
public void init() {
hologram.createHologram();
hologram.showHologram(Bukkit.getOnlinePlayers());
FancyHologramsPlugin.get().getHologramsManager().addHologram(hologram);
FancyHologramsPlugin.get().getHologramManager().addHologram(hologram);
}

@Override
public void clear() {
hologram.hideHologram(Bukkit.getOnlinePlayers());
hologram.deleteHologram();
FancyHologramsPlugin.get().getHologramsManager().removeHologram(hologram);
FancyHologramsPlugin.get().getHologramManager().removeHologram(hologram);
}

@Override
public boolean isInitialized() {
return FancyHologramsPlugin.get().getHologramsManager().getHolograms().contains(hologram);
return ((HologramManagerImpl) FancyHologramsPlugin.get().getHologramManager()).getHolograms().contains(hologram);
}

@Override
Expand Down Expand Up @@ -230,16 +233,17 @@ public void setBackgroundColor(Color color) {
}

@Override
public float getScale() {
public DisplayScale getScale() {
checkHologramInitialized();
return hologram.getData().getScale();
Vector3f scale = hologram.getData().getScale();
return new DisplayScale(scale.x(), scale.y(), scale.z());
}

@Override
public void setScale(float scale) {
public void setScale(DisplayScale scale) {
checkHologramInitialized();
updateTopLocation(scale, hologram.getData().getText().size());
hologram.getData().setScale(scale);
updateTopLocation(scale.y, hologram.getData().getText().size());
hologram.getData().setScale(scale.x, scale.y, scale.z);
updateHologram();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.hsgamer.unihologram.spigot.fancyholograms.provider;

import de.oliver.fancyholograms.FancyHologramsPlugin;
import de.oliver.fancyholograms.FancyHolograms;
import de.oliver.fancyholograms.HologramManagerImpl;
import me.hsgamer.unihologram.common.api.Hologram;
import me.hsgamer.unihologram.common.api.HologramProvider;
import me.hsgamer.unihologram.spigot.fancyholograms.hologram.FHHologram;
Expand Down Expand Up @@ -32,12 +33,12 @@ public static boolean isAvailable() {

@Override
public Optional<Hologram<Location>> getHologram(@NotNull String name) {
return FancyHologramsPlugin.get().getHologramsManager().getHologram(name).map(FHHologram::new);
return FancyHolograms.get().getHologramManager().getHologram(name).map(FHHologram::new);
}

@Override
public Collection<Hologram<Location>> getAllHolograms() {
return FancyHologramsPlugin.get().getHologramsManager().getHolograms().stream().map(FHHologram::new).collect(Collectors.toSet());
return ((HologramManagerImpl) FancyHolograms.get().getHologramManager()).getHolograms().stream().map(FHHologram::new).collect(Collectors.toSet());
}

@Override
Expand Down

0 comments on commit 4b478f9

Please sign in to comment.