diff --git a/gradle.properties b/gradle.properties index 8e296b04..ef07be66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,4 +29,4 @@ description=A modular vanish system for Minecraft servers website=https://sayandev.org author=Syrent -version=1.0.0-rc.5 \ No newline at end of file +version=1.0.0-rc.6 \ No newline at end of file diff --git a/sayanvanish-api/src/main/kotlin/org/sayandev/sayanvanish/api/VanishOptions.kt b/sayanvanish-api/src/main/kotlin/org/sayandev/sayanvanish/api/VanishOptions.kt index fd2e21aa..13ad8a76 100644 --- a/sayanvanish-api/src/main/kotlin/org/sayandev/sayanvanish/api/VanishOptions.kt +++ b/sayanvanish-api/src/main/kotlin/org/sayandev/sayanvanish/api/VanishOptions.kt @@ -7,13 +7,15 @@ import org.sayandev.stickynote.lib.gson.JsonParser data class VanishOptions( var sendMessage: Boolean = true, var notifyStatusChangeToOthers: Boolean = true, - var notifyJoinQuitVanished: Boolean = true + var notifyJoinQuitVanished: Boolean = true, + var isOnJoin: Boolean = false ) { class Builder { private var sendMessage = true private var notifyStatusChangeToOthers = true private var notifyJoinQuitVanished = true + private var isOnJoin = false fun sendMessage(sendMessage: Boolean): Builder { @@ -31,8 +33,13 @@ data class VanishOptions( return this } + fun isOnJoin(isOnJoin: Boolean): Builder { + this.isOnJoin = isOnJoin + return this + } + fun build(): VanishOptions { - return VanishOptions(sendMessage, notifyStatusChangeToOthers, notifyJoinQuitVanished) + return VanishOptions(sendMessage, notifyStatusChangeToOthers, notifyJoinQuitVanished, isOnJoin) } } @@ -41,6 +48,7 @@ data class VanishOptions( json.addProperty("send-message", sendMessage) json.addProperty("notify-status-change-to-others", notifyStatusChangeToOthers) json.addProperty("notify-join-quit-vanished", notifyJoinQuitVanished) + json.addProperty("is-on-join", isOnJoin) return Gson.gson.toJson(json) } @@ -51,7 +59,8 @@ data class VanishOptions( return VanishOptions( json.get("send-message").asBoolean, json.get("notify-status-change-to-others").asBoolean, - json.get("notify-join-quit-vanished").asBoolean + json.get("notify-join-quit-vanished").asBoolean, + json.get("is-on-join").asBoolean ) } diff --git a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureLevel.kt b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureLevel.kt index 33c166b2..60f16585 100644 --- a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureLevel.kt +++ b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureLevel.kt @@ -4,17 +4,14 @@ import org.bukkit.GameMode import org.bukkit.event.EventHandler import org.bukkit.event.player.PlayerGameModeChangeEvent import org.bukkit.event.player.PlayerJoinEvent +import org.sayandev.sayanvanish.api.Permission import org.sayandev.sayanvanish.api.feature.RegisteredFeature import org.sayandev.sayanvanish.bukkit.api.SayanVanishBukkitAPI import org.sayandev.sayanvanish.bukkit.api.SayanVanishBukkitAPI.Companion.user import org.sayandev.sayanvanish.bukkit.api.event.BukkitUserUnVanishEvent import org.sayandev.sayanvanish.bukkit.api.event.BukkitUserVanishEvent import org.sayandev.sayanvanish.bukkit.feature.ListenedFeature -import org.sayandev.stickynote.bukkit.NMSUtils -import org.sayandev.stickynote.bukkit.PacketUtils -import org.sayandev.stickynote.bukkit.onlinePlayers -import org.sayandev.stickynote.bukkit.plugin -import org.sayandev.stickynote.bukkit.runSync +import org.sayandev.stickynote.bukkit.* import org.sayandev.stickynote.lib.spongepowered.configurate.objectmapping.ConfigSerializable @RegisteredFeature @@ -29,8 +26,8 @@ class FeatureLevel( runSync({ val user = event.user for (onlinePlayer in onlinePlayers.filter { it.uniqueId != user.uniqueId }) { - val playerVanishLevel = onlinePlayer.user()?.vanishLevel ?: 0 - if (playerVanishLevel < user.vanishLevel) { + val playerVanishLevel = onlinePlayer.user(false)?.vanishLevel ?: -1 + if (playerVanishLevel < user.vanishLevel || !onlinePlayer.hasPermission(Permission.VANISH.permission())) { user.player()?.let { player -> onlinePlayer.hidePlayer(plugin, player) NMSUtils.sendPacket(onlinePlayer, PacketUtils.getRemoveEntitiesPacket(player.entityId)) @@ -50,7 +47,7 @@ class FeatureLevel( runSync({ val user = event.user for (onlinePlayer in onlinePlayers.filter { it.uniqueId != user.uniqueId }) { - val playerVanishLevel = onlinePlayer.user()?.vanishLevel ?: 0 + val playerVanishLevel = onlinePlayer.user(false)?.vanishLevel ?: -1 if (playerVanishLevel >= user.vanishLevel) { user.player()?.let { player -> NMSUtils.sendPacket(onlinePlayer, PacketUtils.getUpdateGameModePacket(NMSUtils.getServerPlayer(player), player.gameMode)) } } @@ -64,7 +61,7 @@ class FeatureLevel( val player = event.player val user = event.player.user() ?: return for (onlinePlayer in onlinePlayers.filter { it.uniqueId != user.uniqueId }) { - val playerVanishLevel = onlinePlayer.user()?.vanishLevel ?: 0 + val playerVanishLevel = onlinePlayer.user(false)?.vanishLevel ?: -1 if (playerVanishLevel >= user.vanishLevel) { NMSUtils.sendPacket(onlinePlayer, PacketUtils.getUpdateGameModePacket(NMSUtils.getServerPlayer(player), player.gameMode)) } else { @@ -75,13 +72,30 @@ class FeatureLevel( @EventHandler private fun onPlayerJoin(event: PlayerJoinEvent) { - if (!isActive() || seeAsSpectator) return + if (!isActive() || !seeAsSpectator) return runSync({ val player = event.player - val playerVanishLevel = player.user()?.vanishLevel ?: 0 + val playerVanishLevel = player.user(false)?.vanishLevel ?: -1 for (user in SayanVanishBukkitAPI.getInstance().getVanishedUsers().filter { it.player() != null && it.uniqueId != player.uniqueId }) { - if (playerVanishLevel >= user.vanishLevel) { - NMSUtils.sendPacket(player, PacketUtils.getUpdateGameModePacket(NMSUtils.getServerPlayer(player), GameMode.SPECTATOR)) + val vanishedPlayer = user.player() ?: continue + if (playerVanishLevel >= user.vanishLevel && user.hasPermission(Permission.VANISH.permission())) { + NMSUtils.sendPacket(player, PacketUtils.getUpdateGameModePacket(NMSUtils.getServerPlayer(vanishedPlayer), GameMode.SPECTATOR)) + } + } + }, 1) + } + + @EventHandler + private fun hideOthersOnJoin(event: PlayerJoinEvent) { + if (!isActive()) return + runSync({ + val player = event.player + val playerVanishLevel = player.user(false)?.vanishLevel ?: -1 + for (user in SayanVanishBukkitAPI.getInstance().getVanishedUsers().filter { it.player() != null && it.uniqueId != player.uniqueId }) { + val vanishedPlayer = user.player() ?: continue + if (playerVanishLevel < user.vanishLevel || !player.hasPermission(Permission.VANISH.permission())) { + player.hidePlayer(plugin, vanishedPlayer) + NMSUtils.sendPacket(player, PacketUtils.getRemoveEntitiesPacket(vanishedPlayer.entityId)) } } }, 1) diff --git a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureState.kt b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureState.kt index 405bdc24..96895e19 100644 --- a/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureState.kt +++ b/sayanvanish-bukkit/src/main/kotlin/org/sayandev/sayanvanish/bukkit/feature/features/FeatureState.kt @@ -6,16 +6,13 @@ import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerQuitEvent import org.sayandev.sayanvanish.api.Permission import org.sayandev.sayanvanish.api.VanishOptions -import org.sayandev.stickynote.bukkit.utils.AdventureUtils.component import org.sayandev.sayanvanish.api.feature.RegisteredFeature import org.sayandev.sayanvanish.bukkit.api.SayanVanishBukkitAPI import org.sayandev.sayanvanish.bukkit.api.SayanVanishBukkitAPI.Companion.getOrCreateUser import org.sayandev.sayanvanish.bukkit.api.SayanVanishBukkitAPI.Companion.user -import org.sayandev.sayanvanish.bukkit.api.event.BukkitUserUnVanishEvent -import org.sayandev.sayanvanish.bukkit.api.event.BukkitUserVanishEvent import org.sayandev.sayanvanish.bukkit.config.language import org.sayandev.sayanvanish.bukkit.feature.ListenedFeature -import org.sayandev.stickynote.bukkit.onlinePlayers +import org.sayandev.stickynote.bukkit.utils.AdventureUtils.component import org.sayandev.stickynote.lib.kyori.adventure.text.minimessage.tag.resolver.Placeholder import org.sayandev.stickynote.lib.spongepowered.configurate.objectmapping.ConfigSerializable @@ -27,19 +24,14 @@ class FeatureState( val reappearOnQuit: Boolean = false, val checkPermissionOnQuit: Boolean = false, val checkPermissionOnJoin: Boolean = false, - val getFromJoinEvent: Boolean = true, - val getFromQuitEvent: Boolean = true, ) : ListenedFeature("state") { - @Transient var generalJoinMessage: String? = null - @Transient var generalQuitMessage: String? = null - @EventHandler(priority = EventPriority.LOWEST) private fun onJoin(event: PlayerJoinEvent) { if (!isActive()) return val player = event.player val user = player.user(false) - val vanishJoinOptions = VanishOptions.Builder().sendMessage(false).notifyStatusChangeToOthers(false).build() + val vanishJoinOptions = VanishOptions.Builder().sendMessage(false).notifyStatusChangeToOthers(false).isOnJoin(true).build() if (user == null) { val tempUser = player.getOrCreateUser() @@ -79,13 +71,6 @@ class FeatureState( } user.save() - - if (player.user(false)?.isVanished == true) { - if (getFromJoinEvent) { - generalJoinMessage = event.joinMessage - } - event.joinMessage = REMOVAL_MESSAGE_ID - } return } @@ -103,72 +88,11 @@ class FeatureState( } if ((reappearOnQuit && user.isVanished) || (checkPermissionOnQuit && !user.hasPermission(Permission.VANISH))) { - user.unVanish() + user.unVanish(VanishOptions.Builder().isOnJoin(true).build()) } user.isOnline = false user.save() - - if (user.isVanished) { - if (getFromQuitEvent) { - generalQuitMessage = event.quitMessage - } - event.quitMessage = REMOVAL_MESSAGE_ID - } - } - - @EventHandler(priority = EventPriority.MONITOR) - private fun setJoinMessage(event: PlayerJoinEvent) { - if (event.joinMessage != REMOVAL_MESSAGE_ID) { - if (getFromJoinEvent) { - generalJoinMessage = event.joinMessage - } - } else { - event.joinMessage = null - } - } - - @EventHandler(priority = EventPriority.MONITOR) - private fun setQuitMessage(event: PlayerQuitEvent) { - if (event.quitMessage != REMOVAL_MESSAGE_ID) { - if (getFromQuitEvent) { - generalQuitMessage = event.quitMessage - } - } else { - event.quitMessage = null - } - } - - @EventHandler - private fun sendQuitMessageOnVanish(event: BukkitUserVanishEvent) { - val options = event.options - - if (options.sendMessage) { - val quitMessage = generalQuitMessage - if (quitMessage != null) { - for (onlinePlayer in onlinePlayers) { - onlinePlayer.sendMessage(quitMessage) - } - } - } - } - - @EventHandler - private fun sendJoinMessageOnUnVanish(event: BukkitUserUnVanishEvent) { - val options = event.options - - if (options.sendMessage) { - val joinMessage = generalJoinMessage - if (joinMessage != null) { - for (onlinePlayer in onlinePlayers) { - onlinePlayer.sendMessage(joinMessage) - } - } - } - } - - companion object { - private const val REMOVAL_MESSAGE_ID = "SAYANVANISH_DISABLE_MESSAGE" } } \ No newline at end of file