Skip to content

Commit

Permalink
fix: Velocitab compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrent committed Feb 7, 2024
1 parent 2f708bf commit a9fcce5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.velocitypowered.api.proxy.messages.ChannelMessageSource
import ir.syrent.velocityvanish.velocity.bridge.VelocityBridge
import ir.syrent.velocityvanish.velocity.bridge.VelocityBridgeManager
import ir.syrent.velocityvanish.velocity.command.ForceVanishCommand
import ir.syrent.velocityvanish.velocity.hooks.VelocitabHook
import ir.syrent.velocityvanish.velocity.listener.ProxyPingListener
import ir.syrent.velocityvanish.velocity.listener.TabCompleteListener
import ir.syrent.velocityvanish.velocity.vruom.VRUoMPlugin
Expand All @@ -19,6 +20,7 @@ import net.minecrell.serverlistplus.core.ServerListPlusCore
import net.minecrell.serverlistplus.core.replacement.LiteralPlaceholder
import net.minecrell.serverlistplus.core.replacement.ReplacementManager
import net.minecrell.serverlistplus.core.status.StatusResponse
import net.william278.velocitab.api.VelocitabAPI
import org.slf4j.Logger
import java.io.File
import java.nio.file.Path
Expand All @@ -33,6 +35,8 @@ class VelocityVanish @Inject constructor(
lateinit var bridgeManager: VelocityBridgeManager
private set

var velocitabHook: VelocitabHook? = null

/*
* Note: This is not the best way to do this, but for time being it's fine.
* TODO: Create a VanishedPlayer object with serializer and deserializer.
Expand All @@ -46,6 +50,11 @@ class VelocityVanish @Inject constructor(
private fun onProxyInitialization(event: ProxyInitializeEvent) {
instance = this

try {
velocitabHook = VelocitabHook()
VelocitabAPI.getInstance().vanishIntegration = velocitabHook
} catch (_: ClassNotFoundException) { }

initializeMessagingChannels()
initializeListeners()
createFolder()
Expand Down Expand Up @@ -128,7 +137,7 @@ class VelocityVanish @Inject constructor(
}

private fun createFolder() {
val dataFile = VRUoMPlugin.getDataDirectory().toFile()
val dataFile = getDataDirectory().toFile()
if (!dataFile.exists()) {
dataFile.mkdir()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class VelocityBridgeManager(
if (player != null) {
try {
VelocitabAPI.getInstance().vanishPlayer(player)
VelocitabAPI.getInstance().tabList.updateDisplayNames()
} catch (_: NoClassDefFoundError) {}
}
VRuom.getServer().eventManager.fire(VelocityVanishEvent(player, name))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ir.syrent.velocityvanish.velocity.hooks

import ir.syrent.velocityvanish.velocity.VelocityVanish
import ir.syrent.velocityvanish.velocity.vruom.VRuom
import net.william278.velocitab.vanish.VanishIntegration
import kotlin.jvm.optionals.getOrNull

class VelocitabHook : VanishIntegration {


override fun canSee(name: String, otherName: String): Boolean {
return if (VelocityVanish.instance.vanishedPlayers.contains(name) && VelocityVanish.instance.vanishedPlayers.contains(otherName)) true
else if (VRuom.getPlayer(name)?.getOrNull()?.hasPermission("velocityvanish.admin.seevanished") == true) true
else if (VelocityVanish.instance.vanishedPlayers.contains(otherName)) false
else true
}

override fun isVanished(name: String): Boolean {
return VelocityVanish.instance.vanishedPlayers.contains(name)
}

}

0 comments on commit a9fcce5

Please sign in to comment.