Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia support #73

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ repositories {
url = uri("https://repo.codemc.io/repository/maven-snapshots/")
}

maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}

maven {
url = uri("https://www.jitpack.io")
}
Expand Down
20 changes: 20 additions & 0 deletions ensure-java-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

JV=`java -version 2>&1 >/dev/null | head -1`
echo $JV | sed -E 's/^.*version "([^".]*)\.[^"]*".*$/\1/'

if [ "$JV" != 17 ]; then
case "$1" in
install)
echo "Installing SDKMAN..."
curl -s "https://get.sdkman.io" | bash
source ~/.sdkman/bin/sdkman-init.sh
sdk version
sdk install java 17.0.1-open
;;
use)
echo "must source ~/.sdkman/bin/sdkman-init.sh"
exit 1
;;
esac
fi
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
com-github-retrooper-packetevents-spigot = "2.5.0"
org-jetbrains-kotlin-kotlin-stdlib = "1.9.21"
org-spigotmc-spigot-api = "1.16.5-R0.1-SNAPSHOT"
dev-folia-folia-api = "1.19.4-R0.1-SNAPSHOT"

[libraries]
#com-comphenix-protocol-protocollib = { module = "com.comphenix.protocol:ProtocolLib", version.ref = "com-comphenix-protocol-protocollib" }
com-github-retrooper-packetevents-spigot = { module = "com.github.retrooper:packetevents-spigot", version.ref = "com-github-retrooper-packetevents-spigot" }
org-jetbrains-kotlin-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "org-jetbrains-kotlin-kotlin-stdlib" }
org-spigotmc-spigot-api = { module = "org.spigotmc:spigot-api", version.ref = "org-spigotmc-spigot-api" }
dev-folia-folia-api = { module = "dev.folia:folia-api", version.ref = "dev-folia-folia-api" }
21 changes: 20 additions & 1 deletion holoeasy-core/src/main/kotlin/org/holoeasy/HoloEasy.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.holoeasy


import org.bukkit.Chunk
import org.bukkit.Location
import org.bukkit.World
import org.bukkit.entity.Entity
import org.bukkit.plugin.Plugin
import org.holoeasy.action.ClickAction
import org.holoeasy.hologram.Hologram
Expand All @@ -9,15 +13,21 @@ import org.holoeasy.packet.PacketImpl
import org.holoeasy.pool.HologramPool
import org.holoeasy.pool.IHologramPool
import org.holoeasy.pool.InteractiveHologramPool
import org.holoeasy.util.scheduler.MinecraftScheduler


object HoloEasy {

@JvmStatic
@JvmOverloads
fun bind(plugin: Plugin, packetImpl: PacketImpl = PacketImpl.ProtocolLib) {
fun bind(
plugin: Plugin,
packetImpl: PacketImpl = PacketImpl.ProtocolLib,
scheduler: MinecraftScheduler<Plugin, Location, World, Chunk, Entity>
) {
this.PLUGIN = plugin
this.PACKET_IMPL = packetImpl.impl
this.SCHEDULER = scheduler
}

@JvmStatic
Expand Down Expand Up @@ -59,13 +69,22 @@ object HoloEasy {

private var PACKET_IMPL: IPacket? = null

private var SCHEDULER: MinecraftScheduler<Plugin, Location, World, Chunk, Entity>? = null

fun plugin(): Plugin {
if (PLUGIN == null) {
throw IllegalStateException("HoloEasy Plugin is not set")
}
return PLUGIN!!
}

fun scheduler(): MinecraftScheduler<Plugin, Location, World, Chunk, Entity> {
if (SCHEDULER == null) {
throw IllegalStateException("HoloEasy Scheduler is not set")
}
return SCHEDULER!!
}


fun packetImpl(): IPacket {
if (PACKET_IMPL == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.holoeasy.animation

import org.bukkit.scheduler.BukkitTask
import org.holoeasy.HoloEasy
import org.holoeasy.line.LineImpl
import org.holoeasy.util.BukkitFuture
import org.holoeasy.util.scheduler.SchedulerTask

enum class Animations(val task: (LineImpl<*>) -> BukkitTask) {
enum class Animations(val task: (LineImpl<*>) -> SchedulerTask) {

CIRCLE({ line ->
val holo = line.hologram
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion holoeasy-core/src/main/kotlin/org/holoeasy/line/LineImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.holoeasy.HoloEasy
import org.holoeasy.animation.Animations
import org.holoeasy.hologram.Hologram
import org.holoeasy.reactive.Observer
import org.holoeasy.util.scheduler.SchedulerTask
import org.jetbrains.annotations.ApiStatus
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
Expand All @@ -33,7 +34,7 @@ sealed class LineImpl<T>(
abstract override fun update(newValue: T)


private var animationTask: BukkitTask? = null
private var animationTask: SchedulerTask? = null

override fun setAnimation(animation: Animations) {
this.cancelAnimation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HologramPool<T : Hologram>(private val spawnDistance: Double) : Listener,
* Starts the hologram tick.
*/
private fun hologramTick() {
Bukkit.getScheduler().runTaskTimerAsynchronously(HoloEasy.plugin(), Runnable {
HoloEasy.scheduler().createAsyncRepeatingTask(HoloEasy.plugin(), {
for (player in ImmutableList.copyOf(Bukkit.getOnlinePlayers())) {
for (hologram in this.holograms) {
val holoLoc = hologram.location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InteractiveHologramPool<T : Hologram>(

@EventHandler
fun handleInteract(e: PlayerInteractEvent) {
Bukkit.getScheduler().runTaskAsynchronously(HoloEasy.plugin(), Runnable {
HoloEasy.scheduler().runAsyncTask(HoloEasy.plugin(), Runnable {
val player = e.player

if (clickAction == null) {
Expand Down
10 changes: 5 additions & 5 deletions holoeasy-core/src/main/kotlin/org/holoeasy/util/BukkitFuture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ package org.holoeasy.util

import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import org.bukkit.scheduler.BukkitTask
import org.holoeasy.HoloEasy
import org.holoeasy.util.scheduler.SchedulerTask
import java.util.concurrent.CompletableFuture
import java.util.function.BiConsumer
import java.util.function.Supplier

object BukkitFuture {

fun runTaskTimerAsynchronously(l: Long, l1: Long, task: () -> Unit): BukkitTask {
return Bukkit.getScheduler().runTaskTimerAsynchronously(HoloEasy.plugin(), java.lang.Runnable {
fun runTaskTimerAsynchronously(l: Long, l1: Long, task: () -> Unit): SchedulerTask {
return HoloEasy.scheduler().createAsyncRepeatingTask(HoloEasy.plugin(), java.lang.Runnable {
task.invoke()
}, l, l1)
}
Expand All @@ -47,13 +47,13 @@ object BukkitFuture {
supplier: Supplier<T>
): CompletableFuture<T> {
val future = CompletableFuture<T>()
Bukkit.getScheduler().runTaskAsynchronously(plugin, Runnable {
HoloEasy.scheduler().runAsyncTask(plugin) {
try {
future.complete(supplier.get())
} catch (t: Throwable) {
future.completeExceptionally(t)
}
})
}
return future
}

Expand Down
Loading