forked from unldenis/holoeasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
2,862 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.holoeasy | ||
|
||
|
||
import org.bukkit.plugin.Plugin | ||
import org.holoeasy.pool.HologramPool | ||
import org.holoeasy.pool.IHologramPool | ||
import org.holoeasy.pool.InteractiveHologramPool | ||
|
||
object HoloEasy { | ||
|
||
@JvmField | ||
var useLastSupportedVersion: Boolean = false | ||
|
||
@JvmStatic | ||
fun startPool(plugin: Plugin, spawnDistance: Double): IHologramPool { | ||
val simplepool = HologramPool(plugin, spawnDistance) | ||
return simplepool | ||
} | ||
|
||
@JvmStatic | ||
fun startInteractivePool( | ||
plugin: Plugin, spawnDistance: Double, | ||
minHitDistance: Float, maxHitDistance: Float | ||
): IHologramPool { | ||
val simplepool = HologramPool(plugin, spawnDistance) | ||
val interactivepool = InteractiveHologramPool(simplepool, minHitDistance, maxHitDistance) | ||
return interactivepool | ||
} | ||
|
||
|
||
} |
85 changes: 85 additions & 0 deletions
85
core/src/main/kotlin/org/holoeasy/builder/HologramBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.holoeasy.builder; | ||
|
||
import org.holoeasy.builder.interfaces.HologramConfigGroup; | ||
import org.holoeasy.builder.interfaces.HologramSetupGroup; | ||
import org.holoeasy.config.HologramKey; | ||
import org.bukkit.Location; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.holoeasy.hologram.Hologram; | ||
import org.holoeasy.line.ILine; | ||
import org.holoeasy.line.ITextLine; | ||
import org.holoeasy.pool.IHologramPool; | ||
import org.holoeasy.reactive.MutableState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class HologramBuilder { | ||
|
||
static Service getInstance() { | ||
return Service.INSTANCE; | ||
} | ||
|
||
public static Hologram hologram( | ||
@NotNull HologramKey key, @NotNull Location location, @NotNull HologramSetupGroup setupGroup) { | ||
HologramConfig holoConfig = new HologramConfig(key, location); | ||
getInstance().getStaticHologram().set(holoConfig); | ||
setupGroup.setup(); | ||
getInstance().getStaticHologram().remove(); | ||
|
||
Hologram holo = new Hologram(key, holoConfig.location, holoConfig.loader); | ||
holo.load(holoConfig.lines.toArray(new ILine[0])); | ||
return holo; | ||
} | ||
|
||
public static void config(@NotNull HologramConfigGroup configGroup) { | ||
getInstance().config(configGroup); | ||
} | ||
|
||
|
||
public static void textline(@NotNull String text, @NotNull Object... args) { | ||
getInstance().textline( | ||
text, | ||
false, | ||
null, | ||
null, | ||
args.length == 0 ? null : args | ||
); | ||
} | ||
|
||
public static ITextLine clickable(@NotNull String text, @NotNull Object... args) { | ||
return getInstance().textline( | ||
text, | ||
true, | ||
null, | ||
null, | ||
args.length == 0 ? null : args | ||
|
||
); | ||
} | ||
|
||
public static ITextLine clickable(@NotNull String text, float minHitDistance, float maxHitDistance, | ||
@NotNull Object... args) { | ||
return getInstance().textline( | ||
text, | ||
true, | ||
minHitDistance, | ||
maxHitDistance, | ||
args.length == 0 ? null : args | ||
); | ||
} | ||
|
||
public static void item(@NotNull ItemStack block) { | ||
getInstance().itemline(block); | ||
} | ||
|
||
public static void item(@NotNull MutableState<ItemStack> block) { | ||
getInstance().itemlineMutable(block); | ||
} | ||
|
||
public static void customline(@NotNull ILine<?> customLine) { | ||
getInstance().customLine(customLine); | ||
} | ||
|
||
public static <T> MutableState<T> mutableStateOf(@NotNull T initialValue) { | ||
return new MutableState<>(initialValue); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
core/src/main/kotlin/org/holoeasy/builder/HologramConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.holoeasy.builder; | ||
|
||
import org.holoeasy.config.HologramKey; | ||
import org.bukkit.Location; | ||
import org.holoeasy.hologram.IHologramLoader; | ||
import org.holoeasy.hologram.TextBlockStandardLoader; | ||
import org.holoeasy.line.ILine; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class HologramConfig { | ||
|
||
@NotNull | ||
final HologramKey key; | ||
@NotNull | ||
final Location location; | ||
final List<ILine<?>> lines = new ArrayList<>(); | ||
public IHologramLoader loader = new TextBlockStandardLoader(); | ||
|
||
HologramConfig(@NotNull HologramKey key, @NotNull Location location) { | ||
this.key = key; | ||
this.location = location; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.holoeasy.builder | ||
|
||
|
||
import org.bukkit.inventory.ItemStack | ||
import org.holoeasy.builder.interfaces.HologramConfigGroup | ||
import org.holoeasy.hologram.TextBlockStandardLoader | ||
import org.holoeasy.line.* | ||
import org.holoeasy.reactive.MutableState | ||
import kotlin.math.min | ||
|
||
object Service { | ||
|
||
val staticHologram: ThreadLocal<HologramConfig> = ThreadLocal() | ||
|
||
private fun getStaticHolo(): HologramConfig { | ||
val holo = staticHologram.get() ?: throw RuntimeException("You must call config() inside hologram block") | ||
return holo | ||
} | ||
|
||
fun config(configGroup: HologramConfigGroup) { | ||
val config = getStaticHolo() | ||
|
||
configGroup.configure(config) | ||
|
||
|
||
config.loader = config.loader ?: TextBlockStandardLoader() | ||
} | ||
|
||
@JvmOverloads | ||
fun textline( | ||
text: String, clickable: Boolean = false, minHitDistance: Float? = null, | ||
maxHitDistance: Float? = null, args: Array<*>? = null | ||
) : ITextLine { | ||
val holo = getStaticHolo() | ||
|
||
if (minHitDistance == null || maxHitDistance == null) { | ||
if(holo.key.pool == null && clickable) { | ||
throw IllegalStateException("This hologram is not in a pool,so use the method #clickable(text, minHitDistance, maxHitDistance)") | ||
} | ||
|
||
val textLine = TextLine(holo.key.plugin, text, clickable = clickable, args = args) | ||
holo.lines.add(textLine) | ||
return textLine | ||
|
||
} | ||
val textLine = TextLine(holo.key.plugin, text, clickable = false, args = args) | ||
val clickableTextLine = ClickableTextLine(textLine, minHitDistance, maxHitDistance) | ||
holo.lines.add(clickableTextLine) | ||
return clickableTextLine | ||
} | ||
|
||
fun itemline(block: ItemStack) { | ||
val holo = getStaticHolo() | ||
val blockline = BlockLine(holo.key.plugin, block) | ||
holo.lines.add(blockline) | ||
} | ||
|
||
fun itemlineMutable(block: MutableState<ItemStack>) { | ||
val holo = getStaticHolo() | ||
val blockline = BlockLine(holo.key.plugin, block) | ||
holo.lines.add(blockline) | ||
} | ||
|
||
fun customLine(customLine: ILine<*>) { | ||
val holo = getStaticHolo() | ||
holo.lines.add(customLine) | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/kotlin/org/holoeasy/builder/interfaces/HologramConfigGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.holoeasy.builder.interfaces; | ||
|
||
import org.holoeasy.builder.HologramConfig; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@FunctionalInterface | ||
public interface HologramConfigGroup { | ||
void configure(@NotNull HologramConfig context); | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/kotlin/org/holoeasy/builder/interfaces/HologramSetupGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.holoeasy.builder.interfaces; | ||
|
||
@FunctionalInterface | ||
public interface HologramSetupGroup { | ||
void setup(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.holoeasy.config; | ||
|
||
import org.bukkit.plugin.Plugin; | ||
import org.holoeasy.pool.IHologramPool; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
public class HologramKey { | ||
|
||
private final Plugin plugin; | ||
private final String id; | ||
|
||
private final IHologramPool pool; | ||
|
||
|
||
public HologramKey(@NotNull Plugin plugin, @NotNull String id, @Nullable IHologramPool pool) { | ||
this.plugin = plugin; | ||
this.id = id; | ||
this.pool = pool; | ||
} | ||
|
||
public HologramKey(@NotNull Plugin plugin, @NotNull String id) { | ||
this(plugin, id, null); | ||
} | ||
|
||
public HologramKey(@NotNull IHologramPool pool, @NotNull String id) { | ||
this(pool.getPlugin(), id, pool); | ||
} | ||
|
||
@NotNull | ||
public Plugin getPlugin() { | ||
return plugin; | ||
} | ||
|
||
@NotNull | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Nullable | ||
public IHologramPool getPool() { | ||
return pool; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(plugin, id, pool); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
HologramKey that = (HologramKey) o; | ||
return Objects.equals(plugin, that.plugin) && Objects.equals(id, that.id) && Objects.equals(pool, that.pool); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HologramKey{" + | ||
"plugin=" + plugin + | ||
", id='" + id + '\'' + | ||
", pool=" + pool + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.holoeasy.ext | ||
|
||
import kotlin.math.floor | ||
|
||
val Double.compressAngle: Byte | ||
get() = (this * 256f / 360f).toInt().toByte() | ||
|
||
val Double.fixCoordinate: Int | ||
get() = floor(this * 32.0).toInt() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.holoeasy.ext | ||
|
||
import com.comphenix.protocol.wrappers.BukkitConverters | ||
import org.bukkit.inventory.ItemStack | ||
|
||
|
||
fun ItemStack.bukkitGeneric() : Any { | ||
return BukkitConverters.getItemStackConverter().getGeneric(this) | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/kotlin/org/holoeasy/ext/PacketContainerExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.holoeasy.ext | ||
|
||
import com.comphenix.protocol.ProtocolLibrary | ||
import com.comphenix.protocol.events.PacketContainer | ||
import com.comphenix.protocol.utility.MinecraftVersion | ||
import com.comphenix.protocol.wrappers.WrappedDataValue | ||
import com.comphenix.protocol.wrappers.WrappedDataWatcher | ||
import com.google.common.collect.Lists | ||
import org.bukkit.entity.Player | ||
import java.util.* | ||
|
||
fun PacketContainer.send(player: Player) { | ||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, this) | ||
} | ||
|
||
operator fun PacketContainer.invoke(player: Player) { | ||
send(player) | ||
} | ||
|
||
fun PacketContainer.parse119(watcher: WrappedDataWatcher) { | ||
if (MinecraftVersion.getCurrentVersion().isAtLeast(MinecraftVersion("1.19.3"))) { | ||
val wrappedDataValueList: MutableList<WrappedDataValue> = Lists.newArrayList() | ||
watcher.watchableObjects.stream().filter(Objects::nonNull).forEach { entry -> | ||
val dataWatcherObject: WrappedDataWatcher.WrappedDataWatcherObject = entry.watcherObject | ||
wrappedDataValueList.add( | ||
WrappedDataValue( | ||
dataWatcherObject.index, | ||
dataWatcherObject.serializer, | ||
entry.rawValue | ||
) | ||
) | ||
} | ||
dataValueCollectionModifier.write(0, wrappedDataValueList) | ||
} else { | ||
watchableCollectionModifier.write(0, watcher.watchableObjects) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/kotlin/org/holoeasy/ext/StructureModifierExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.holoeasy.ext | ||
|
||
import com.comphenix.protocol.reflect.StructureModifier | ||
|
||
operator fun <T> StructureModifier<T>.set(index: Int, value: T) { | ||
write(index, value) | ||
} |
Oops, something went wrong.