Skip to content

Commit

Permalink
finish builder
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 28, 2024
1 parent bc4f454 commit 43a47a2
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.oliver.fancyholograms.api.data.builder;

import de.oliver.fancyholograms.api.data.BlockHologramData;
import org.bukkit.Location;
import org.bukkit.Material;

public class BlockHologramBuilder extends HologramBuilder{

public BlockHologramBuilder(String name, Location location) {
super();
this.data = new BlockHologramData(name, location);
}

public static BlockHologramBuilder create(String name, Location location) {
return new BlockHologramBuilder(name, location);
}

public BlockHologramBuilder block(Material block) {
((BlockHologramData) data).setBlock(block);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,79 @@
package de.oliver.fancyholograms.api.data.builder;

import de.oliver.fancyholograms.api.FancyHolograms;
import de.oliver.fancyholograms.api.data.BlockHologramData;
import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancyholograms.api.data.ItemHologramData;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.data.DisplayHologramData;
import de.oliver.fancyholograms.api.data.property.Visibility;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.api.hologram.HologramType;
import org.bukkit.Location;
import org.bukkit.entity.Display;
import org.joml.Vector3f;

public class HologramBuilder {
public abstract class HologramBuilder {

private final HologramData data;
protected DisplayHologramData data;

private HologramBuilder(HologramType type, String name, Location location) {
switch (type){
case TEXT -> data = new TextHologramData(name, location);
case ITEM -> data = new ItemHologramData(name, location);
case BLOCK -> data = new BlockHologramData(name, location);
default -> throw new UnsupportedOperationException("Unsupported hologram type: " + type);
}
}

public static HologramBuilder create(HologramType type, String name, Location location) {
return new HologramBuilder(type, name, location);
HologramBuilder() {
}

public Hologram build() {
return FancyHolograms.get().getHologramFactory().apply(data);
}

// The following methods are setters for the HologramData class

public HologramBuilder visibilityDistance(int distance) {
data.setVisibilityDistance(distance);
return this;
}

public HologramBuilder visibility(Visibility visibility) {
data.setVisibility(visibility);
return this;
}

public HologramBuilder persistent(boolean persistent) {
data.setPersistent(persistent);
return this;
}

public HologramBuilder linkedNpcName(String linkedNpcName) {
data.setLinkedNpcName(linkedNpcName);
return this;
}

// The following methods are specific to the DisplayHologramData class

public HologramBuilder billboard(Display.Billboard billboard) {
data.setBillboard(billboard);
return this;
}

public HologramBuilder scale(float x, float y, float z) {
data.setScale(new Vector3f(x, y, z));
return this;
}

public HologramBuilder translation(float x, float y, float z) {
data.setTranslation(new Vector3f(x, y, z));
return this;
}

public HologramBuilder brightness(int blockLight, int skyLight) {
data.setBrightness(new Display.Brightness(blockLight, skyLight));
return this;
}

public HologramBuilder shadowRadius(float shadowRadius) {
data.setShadowRadius(shadowRadius);
return this;
}

public HologramBuilder shadowStrength(float shadowStrength) {
data.setShadowStrength(shadowStrength);
return this;
}

public HologramBuilder interpolationDuration(int interpolationDuration) {
data.setInterpolationDuration(interpolationDuration);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.oliver.fancyholograms.api.data.builder;

import de.oliver.fancyholograms.api.data.ItemHologramData;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

public class ItemHologramBuilder extends HologramBuilder{

public ItemHologramBuilder(String name, Location location) {
super();
this.data = new ItemHologramData(name, location);
}

public static ItemHologramBuilder create(String name, Location location) {
return new ItemHologramBuilder(name, location);
}

public ItemHologramBuilder item(ItemStack item) {
((ItemHologramData) data).setItemStack(item);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.oliver.fancyholograms.api.data.builder;

import de.oliver.fancyholograms.api.data.TextHologramData;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.entity.TextDisplay;

import java.util.List;

public class TextHologramBuilder extends HologramBuilder{

private TextHologramBuilder(String name, Location location) {
super();
this.data = new TextHologramData(name, location);
}

public static TextHologramBuilder create(String name, Location location) {
return new TextHologramBuilder(name, location);
}

public TextHologramBuilder text(List<String> text) {
((TextHologramData) data).setText(text);
return this;
}

public TextHologramBuilder background(Color background) {
((TextHologramData) data).setBackground(background);
return this;
}

public TextHologramBuilder textAlignment(TextDisplay.TextAlignment textAlignment) {
((TextHologramData) data).setTextAlignment(textAlignment);
return this;
}

public TextHologramBuilder textShadow(boolean textShadow) {
((TextHologramData) data).setTextShadow(textShadow);
return this;
}

public TextHologramBuilder seeThrough(boolean seeThrough) {
((TextHologramData) data).setSeeThrough(seeThrough);
return this;
}

public TextHologramBuilder updateTextInterval(int updateTextInterval) {
((TextHologramData) data).setTextUpdateInterval(updateTextInterval);
return this;
}

}

0 comments on commit 43a47a2

Please sign in to comment.