Skip to content

Commit

Permalink
fix: updated cmi api
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrent committed Apr 30, 2024
1 parent bddb3d9 commit cdc48cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ publishing {
}

val extraDependencies = mapOf(
"CMI.jar" to "https://www.zrips.net/wp-content/uploads/2021/09/CMI9.0.0.0API.jar",
"CMI.jar" to "https://github.com/Zrips/CMI-API/releases/download/9.7.0.1/CMI-API9.7.0.1.jar",
"NexEngine.jar" to "https://github.com/nulli0n/NexEngine-spigot/releases/download/v2.2.11/NexEngine.jar",
"SunLight.jar" to "https://www.dropbox.com/scl/fi/mmu7g32vj6oitkja65cws/SunLight-3.9.4.jar?rlkey=tqxgcy80yccxh80yzl24ubs7b&dl=1",
"ServerListPlus.jar" to "https://ci.codemc.io/job/Minecrell/job/ServerListPlus/lastSuccessfulBuild/artifact/Velocity/build/libs/ServerListPlus-3.5.1-SNAPSHOT-Velocity.jar",
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ir.syrent.velocityvanish.spigot.core

import com.Zrips.CMI.CMI
import com.Zrips.CMI.commands.list.vanishedit
import com.Zrips.CMI.Modules.Vanish.VanishAction
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.wrappers.EnumWrappers
Expand Down Expand Up @@ -155,21 +155,23 @@ class VanishManager(
player.scoreboard.getTeam("Vanished")?.removeEntry(player.name)
}

fun vanish(player: Player, sendQuitMessage: Boolean = true, callPostEvent: Boolean = false) {
vanish(player, sendQuitMessage, callPostEvent, false)
fun vanish(player: Player, sendQuitMessage: Boolean = true, callPostEvent: Boolean = false, sendPluginMessage: Boolean = true) {
vanish(player, sendQuitMessage, callPostEvent, false, sendPluginMessage = sendPluginMessage)
}

fun vanish(player: Player, sendQuitMessage: Boolean = true, callPostEvent: Boolean = false, notifyAdmins: Boolean = false) {
fun vanish(player: Player, sendQuitMessage: Boolean = true, callPostEvent: Boolean = false, notifyAdmins: Boolean = false, sendPluginMessage: Boolean = true) {
val preVanishEvent = PreVanishEvent(player, sendQuitMessage)
VelocityVanishSpigot.instance.server.pluginManager.callEvent(preVanishEvent)

if (preVanishEvent.isCancelled) return

plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)
// Because plugin messaging is the most reliable thing in the world i have to send the vanish update after 20 ticks to make sure the message is received on the Velocity side
Ruom.runSync({
if (sendPluginMessage) {
plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)
}, 20)
// Because plugin messaging is the most reliable thing in the world i have to send the vanish update after 20 ticks to make sure the message is received on the Velocity side
Ruom.runSync({
plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)
}, 20)
}
setMeta(player, true)

updateTabState(player, GameMode.SPECTATOR)
Expand Down Expand Up @@ -231,8 +233,12 @@ class VanishManager(
val cmiUser = CMI.getInstance().playerManager.getUser(player)
cmiUser.isVanished = true
CMI.getInstance().vanishManager.addPlayer(cmiUser)
cmiUser.vanish.set(vanishedit.VanishAction.isVanished, true)
cmiUser.vanish.set(vanishedit.VanishAction.informOnJoin, false)
cmiUser.vanish.set(VanishAction.isVanished, true)
cmiUser.vanish.set(VanishAction.informOnJoin, false)
cmiUser.vanish.set(VanishAction.PrivateMessages, false)
cmiUser.vanish.set(VanishAction.afkcommands, false)
cmiUser.vanish.set(VanishAction.deathMessages, false)
cmiUser.vanish.set(VanishAction.fakeJoinLeave, false)
cmiUser.updateVanishMode()
}

Expand Down Expand Up @@ -285,16 +291,18 @@ class VanishManager(
}


fun unVanish(player: Player, sendJoinMessage: Boolean = true, callPostEvent: Boolean = false) {
unVanish(player, sendJoinMessage, callPostEvent, false)
fun unVanish(player: Player, sendJoinMessage: Boolean = true, callPostEvent: Boolean = false, sendPluginMessage: Boolean = true) {
unVanish(player, sendJoinMessage, callPostEvent, false, sendPluginMessage = sendPluginMessage)
}

fun unVanish(player: Player, sendJoinMessage: Boolean = true, callPostEvent: Boolean = false, notifyAdmins: Boolean = false) {
fun unVanish(player: Player, sendJoinMessage: Boolean = true, callPostEvent: Boolean = false, notifyAdmins: Boolean = false, sendPluginMessage: Boolean = true) {
val preUnVanishEvent = PreUnVanishEvent(player, sendJoinMessage)
VelocityVanishSpigot.instance.server.pluginManager.callEvent(preUnVanishEvent)

if (preUnVanishEvent.isCancelled) return
plugin.bridgeManager?.updateVanishedPlayersRequest(player, false)
if (sendPluginMessage) {
plugin.bridgeManager?.updateVanishedPlayersRequest(player, false)
}

setMeta(player, false)

Expand Down Expand Up @@ -335,8 +343,12 @@ class VanishManager(
val cmiUser = CMI.getInstance().playerManager.getUser(player)
cmiUser.isVanished = false
CMI.getInstance().vanishManager.removePlayer(cmiUser)
cmiUser.vanish.set(vanishedit.VanishAction.isVanished, false)
cmiUser.vanish.set(vanishedit.VanishAction.informOnJoin, true)
cmiUser.vanish.set(VanishAction.isVanished, false)
cmiUser.vanish.set(VanishAction.informOnJoin, false)
cmiUser.vanish.set(VanishAction.PrivateMessages, true)
cmiUser.vanish.set(VanishAction.afkcommands, true)
cmiUser.vanish.set(VanishAction.deathMessages, true)
cmiUser.vanish.set(VanishAction.fakeJoinLeave, false)
cmiUser.updateVanishMode()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.metadata.FixedMetadataValue
import org.bukkit.permissions.Permission
import org.bukkit.permissions.PermissionDefault

class PlayerJoinListener(
private val plugin: VelocityVanishSpigot
Expand Down Expand Up @@ -48,13 +50,13 @@ class PlayerJoinListener(
plugin.vanishManager.vanish(player, sendQuitMessage = false, callPostEvent = true)
event.joinMessage = null
} else {
if (player.hasPermission("velocityvanish.action.vanish.onjoin")) {
if (player.hasPermission(Permission("velocityvanish.action.vanish.onjoin", PermissionDefault.FALSE))) {
plugin.vanishManager.vanish(player, sendQuitMessage = false, callPostEvent = true)
event.joinMessage = null
} else if (player.hasPermission("velocityvanish.action.vanish.force") && Settings.forceVanishIfFirst && Ruom.onlinePlayers.size <= 1) {
if (!Settings.remember) return
player.sendMessage(Message.FORCE_VANISHED)
plugin.vanishManager.vanish(player, sendQuitMessage = false, callPostEvent = true)
plugin.vanishManager.vanish(player, sendQuitMessage = false, callPostEvent = true, sendPluginMessage = false)
event.joinMessage = null

Ruom.runSync({
Expand Down

0 comments on commit cdc48cd

Please sign in to comment.