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

Reference intave api classes later #2

Open
wants to merge 2 commits into
base: main
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
11 changes: 2 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.opencollab.dev/maven-snapshots")
maven {
name = "github"
url = uri("https://maven.pkg.github.com/intave/access")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
maven("https://repo.janmm14.de/repository/intave/")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
compileOnly("de.jpx3.intave.access:intave-access:14.3.5")
compileOnly("de.jpx3.intave.access:intave-access:14.4.2")
compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT")
}

Expand Down
47 changes: 47 additions & 0 deletions src/main/kotlin/de/intave/bedrock/BedrockSupport.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.intave.bedrock

import de.jpx3.intave.IntaveAccessor
import de.jpx3.intave.access.IntaveAccess
import de.jpx3.intave.access.IntaveColdException
import de.jpx3.intave.access.player.trust.TrustFactor
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.geysermc.floodgate.api.FloodgateApi
import java.lang.ref.WeakReference

class BedrockSupport(private val plugin: BedrockSupportPlugin) : Listener {
private val accessReference: WeakReference<IntaveAccess> = IntaveAccessor.weakAccess()

init {
Bukkit.getPluginManager().registerEvents(this, plugin)
}

@EventHandler
private fun receiveJoin(event: PlayerJoinEvent) {
check(0, event.player)
}

/**
* Checks if the player's floodgate state changes in the next 30 ticks (3 x 10 ticks) to re-assign the
* trust-factor if anything went wrong
*
* Once the player is marked as bedrock player no re-check will be scheduled
*
* @param tick The current ticks
* @param player The player being checked
*/
private fun check(tick: Int, player: Player) {
val access = accessReference.get() ?: throw IntaveColdException("Intave offline")
val intavePlayer = access.player(player)
if (FloodgateApi.getInstance().isFloodgatePlayer(player.uniqueId)) {
intavePlayer.setTrustFactor(TrustFactor.BYPASS)
} else if (tick < 3) {
// Schedule a new check in 10 ticks
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, { check(tick + 1, player) }, 10)
}
}

}
50 changes: 5 additions & 45 deletions src/main/kotlin/de/intave/bedrock/BedrockSupportPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,56 +1,16 @@
package de.intave.bedrock

import de.jpx3.intave.IntaveAccessor
import de.jpx3.intave.access.IntaveAccess
import de.jpx3.intave.access.IntaveColdException
import de.jpx3.intave.access.player.trust.TrustFactor
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.plugin.java.JavaPlugin
import org.geysermc.floodgate.api.FloodgateApi
import java.lang.ref.WeakReference

class BedrockSupportPlugin : JavaPlugin(), Listener {
private lateinit var accessReference: WeakReference<IntaveAccess>

override fun onEnable() {
enableBedrockSupport()
}

/**
* Enables the [BedrockSupportPlugin] by creating a join listener to automatically assign the [TrustFactor.BYPASS]
* to bedrock players
*/
private fun enableBedrockSupport() {
accessReference = IntaveAccessor.weakAccess()
Bukkit.getPluginManager().registerEvents(this, this)
}

@EventHandler
private fun receiveJoin(event: PlayerJoinEvent) {
check(0, event.player)
}

/**
* Checks if the player's floodgate state changes in the next 30 ticks (3 x 10 ticks) to re-assign the
* trust-factor if anything went wrong
*
* Once the player is marked as bedrock player no re-check will be scheduled
*
* @param tick The current ticks
* @param player The player being checked
*/
private fun check(tick: Int, player: Player) {
val access = accessReference.get() ?: throw IntaveColdException("Intave offline")
val intavePlayer = access.player(player)
if (FloodgateApi.getInstance().isFloodgatePlayer(player.uniqueId)) {
intavePlayer.setTrustFactor(TrustFactor.BYPASS)
} else if (tick < 3) {
// Schedule a new check in 10 ticks
Bukkit.getScheduler().scheduleSyncDelayedTask(this, { check(tick + 1, player) }, 10)
}
// delay any intialization to make sure that intave api classes are loaded
Bukkit.getScheduler().scheduleSyncDelayedTask(this, {
BedrockSupport(this)
logger.info("Bedrock support enabled");
}, 1)
}
}