Skip to content

Commit

Permalink
Merge pull request #1 from TheNextLvl-net/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
NonSwag authored Oct 22, 2023
2 parents ef941c5 + 7b777a3 commit 5112dda
Show file tree
Hide file tree
Showing 56 changed files with 562 additions and 1,110 deletions.
4 changes: 2 additions & 2 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ java {
}

group = rootProject.group
version = "1.0.2"
version = "2.0.0"

repositories {
mavenCentral()
Expand All @@ -19,7 +19,7 @@ repositories {

dependencies {
compileOnly("org.projectlombok:lombok:1.18.28")
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")

compileOnly("net.thenextlvl.core:annotations:2.0.0")

Expand Down
47 changes: 0 additions & 47 deletions api/src/main/java/net/thenextlvl/hologram/api/Hologram.java

This file was deleted.

86 changes: 22 additions & 64 deletions api/src/main/java/net/thenextlvl/hologram/api/HologramFactory.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,43 @@
package net.thenextlvl.hologram.api;

import net.thenextlvl.hologram.api.line.BlockLine;
import net.thenextlvl.hologram.api.line.HologramLine;
import net.thenextlvl.hologram.api.line.ItemLine;
import net.thenextlvl.hologram.api.line.TextLine;
import net.kyori.adventure.text.Component;
import net.thenextlvl.hologram.api.hologram.BlockHologram;
import net.thenextlvl.hologram.api.hologram.Hologram;
import net.thenextlvl.hologram.api.hologram.ItemHologram;
import net.thenextlvl.hologram.api.hologram.TextHologram;
import org.bukkit.Location;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.TextDisplay;

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Function;
import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.ItemStack;

/**
* A factory that creates {@link Hologram holograms} and {@link HologramLine hologram lines}
* A factory that creates {@link Hologram holograms}
*/
public interface HologramFactory {
/**
* Create a new hologram object
*
* @param location the location of the hologram
* @param lines the lines of the hologram
* @return the new hologram
*/
Hologram createHologram(Location location, Collection<? extends HologramLine> lines);

/**
* Create a new hologram object
* Create a new text hologram object
*
* @param location the location of the hologram
* @param lines the lines of the hologram
* @return the new hologram
*/
Hologram createHologram(Location location, HologramLine... lines);

/**
* Creates a new line of the type block
*
* @param function provides the block-display and returns the offset
* @return the new line
*/
BlockLine createBlockLine(Function<BlockDisplay, Number> function);

/**
* Creates a new line of the type block
*
* @param consumer provides the block-display
* @return the new line
*/
BlockLine createBlockLine(Consumer<BlockDisplay> consumer);

/**
* Creates a new line of the type item
*
* @param function provides the item-display and returns the offset
* @return the new line
* @param text the text of the hologram
* @return the new text hologram
*/
ItemLine createItemLine(Function<ItemDisplay, Number> function);
TextHologram createHologram(Location location, Component text);

/**
* Creates a new line of the type item
* Create a new block hologram object
*
* @param consumer provides the item-display
* @return the new line
*/
ItemLine createItemLine(Consumer<ItemDisplay> consumer);

/**
* Creates a new line of the type text
*
* @param function provides the text-display and returns the offset
* @return the new line
* @param location the location of the hologram
* @param block the block of the hologram
* @return the new block hologram
*/
TextLine createTextLine(Function<TextDisplay, Number> function);
BlockHologram createHologram(Location location, BlockData block);

/**
* Creates a new line of the type text
* Create a new item hologram object
*
* @param consumer provides the text-display
* @return the new line
* @param location the location of the hologram
* @param itemStack the item of the hologram
* @return the new item hologram
*/
TextLine createTextLine(Consumer<TextDisplay> consumer);
ItemHologram createHologram(Location location, ItemStack itemStack);
}
34 changes: 24 additions & 10 deletions api/src/main/java/net/thenextlvl/hologram/api/HologramLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.thenextlvl.hologram.api;

import net.thenextlvl.hologram.api.hologram.Hologram;
import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -29,7 +30,9 @@ public interface HologramLoader {
* @see HologramLoader#getViewers(Hologram)
* @see HologramLoader#unload(Hologram, Player)
*/
void unload(Hologram hologram);
default void unload(Hologram hologram) {
getViewers(hologram).forEach(player -> unload(hologram, player));
}

/**
* Unloads the hologram for the specified player
Expand All @@ -51,7 +54,9 @@ public interface HologramLoader {
* @see HologramLoader#getViewers(Hologram)
* @see HologramLoader#update(Hologram, Player)
*/
void update(Hologram hologram) throws NullPointerException;
default void update(Hologram hologram) throws NullPointerException {
getViewers(hologram).forEach(player -> update(hologram, player));
}

/**
* Updates the hologram for the specified player
Expand All @@ -72,10 +77,14 @@ public interface HologramLoader {
*
* @param hologram the hologram to teleport
* @param location the new location of the hologram
* @throws NullPointerException thrown if the
* {@link Location#getWorld() world} of the hologram is null
* @throws IllegalArgumentException thrown if the current and new
* {@link Location#getWorld() world} don't match
* @throws NullPointerException thrown if the
* {@link Location#getWorld() world} of the hologram is null
*/
void teleport(Hologram hologram, Location location) throws NullPointerException;
default void teleport(Hologram hologram, Location location) throws IllegalArgumentException, NullPointerException {
getViewers(hologram).forEach(player -> teleport(hologram, location, player));
}

/**
* Teleport the hologram for a specific player to a new location
Expand All @@ -84,8 +93,9 @@ public interface HologramLoader {
* @param location the new location of the hologram
* @param player the player to teleport the hologram for
* @throws IllegalArgumentException thrown if the hologram is
* {@link HologramLoader#isLoaded(Hologram, Player) not loaded} or not
* {@link HologramLoader#canSee(Player, Hologram) visible} to the player
* {@link HologramLoader#isLoaded(Hologram, Player) not loaded}, not
* {@link HologramLoader#canSee(Player, Hologram) visible} to the player or
* the current and new {@link Location#getWorld() world} don't match
* @throws NullPointerException thrown if the
* {@link Location#getWorld() world} of the hologram is null
*/
Expand All @@ -99,7 +109,9 @@ public interface HologramLoader {
* @return true if the hologram is loaded for the player
* @see HologramLoader#getViewers(Hologram)
*/
boolean isLoaded(Hologram hologram, Player player);
default boolean isLoaded(Hologram hologram, Player player) {
return getHolograms(player).contains(hologram);
}

/**
* Checks if the player could possibly see the hologram
Expand All @@ -108,7 +120,9 @@ public interface HologramLoader {
* @param hologram the hologram
* @return true if the hologram can be seen by the player
*/
boolean canSee(Player player, Hologram hologram);
default boolean canSee(Player player, Hologram hologram) {
return player.getWorld().equals(hologram.getLocation().getWorld());
}

/**
* All the players the hologram is loaded for
Expand All @@ -125,5 +139,5 @@ public interface HologramLoader {
* @param player the player
* @return the holograms currently loaded for the player
*/
Collection<? extends Hologram> getHolograms(Player player);
Collection<Hologram> getHolograms(Player player);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.thenextlvl.hologram.api;

import net.thenextlvl.hologram.api.hologram.Hologram;

import java.util.Collection;

/**
Expand All @@ -11,7 +13,7 @@ public interface HologramRegistry {
*
* @return the registered holograms
*/
Collection<? extends Hologram> getHolograms();
Collection<Hologram> getHolograms();

/**
* Register a new hologram
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.thenextlvl.hologram.api.hologram;

import org.bukkit.entity.BlockDisplay;

/**
* An interface that represents a hologram displaying a block
*/
public interface BlockHologram extends Hologram, BlockDisplay {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.thenextlvl.hologram.api.hologram;

import org.bukkit.Location;
import org.bukkit.entity.Display;

/**
* An interface that represents a hologram
*/
public interface Hologram extends Display {
/**
* Get the location of the hologram
*
* @return the current location the hologram is
*/
Location getLocation();

/**
* Set the location of the hologram<br>
* <i>Only applies on load, not for teleportation or updating</i>
*
* @param location the location the hologram should appear
*/
void setLocation(Location location);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.thenextlvl.hologram.api.hologram;

import org.bukkit.entity.ItemDisplay;

/**
* An interface that represents a hologram displaying an item
*/
public interface ItemHologram extends Hologram, ItemDisplay {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.thenextlvl.hologram.api.hologram;

import org.bukkit.entity.TextDisplay;

/**
* An interface that represents a hologram displaying a text
*/
public interface TextHologram extends Hologram, TextDisplay {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@MethodsReturnNotNullByDefault
@ParametersAreNotNullByDefault
package net.thenextlvl.hologram.v1_19_R3.line;
package net.thenextlvl.hologram.api.hologram;

import core.annotation.MethodsReturnNotNullByDefault;
import core.annotation.ParametersAreNotNullByDefault;
11 changes: 0 additions & 11 deletions api/src/main/java/net/thenextlvl/hologram/api/line/BlockLine.java

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions api/src/main/java/net/thenextlvl/hologram/api/line/ItemLine.java

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions api/src/main/java/net/thenextlvl/hologram/api/line/TextLine.java

This file was deleted.

Loading

0 comments on commit 5112dda

Please sign in to comment.