Skip to content

Commit

Permalink
fix: use vanished player as placeholder target for some messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrent committed Jan 17, 2024
1 parent a9bfdba commit 72910fb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.27.2
version=3.27.3
plugin-name=VelocityVanish

# Hangar properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class VanishManager(
plugin.vanishedNames.add(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)

val quitMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.QUIT_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName)))
val quitMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.QUIT_MESSAGE, player, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName)))
if (quitMessage.isNotBlank() && quitMessage.isNotEmpty() && sendQuitMessage && Settings.fakeJoinLeaveMessage) {
Ruom.broadcast(quitMessage.component())
}
Expand All @@ -289,7 +289,7 @@ class VanishManager(

if (notifyAdmins) {
for (staff in Ruom.onlinePlayers.filter { it.hasPermission("velocityvanish.admin.notify") && it != player }) {
staff.sendMessage(Message.VANISH_NOTIFY, TextReplacement("player", player.name))
staff.sendMessage(Message.VANISH_NOTIFY, player, TextReplacement("player", player.name))
}
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ class VanishManager(
plugin.vanishedNames.remove(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, false)

val joinMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.JOIN_MESSAGE, TextReplacement("player_displayname", player.displayName), TextReplacement("player", player.name)))
val joinMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.JOIN_MESSAGE, player, TextReplacement("player_displayname", player.displayName), TextReplacement("player", player.name)))
if (joinMessage.isNotBlank() && joinMessage.isNotEmpty() && sendJoinMessage && Settings.fakeJoinLeaveMessage) {
Ruom.broadcast(joinMessage.component())
}
Expand All @@ -395,7 +395,7 @@ class VanishManager(

if (notifyAdmins) {
for (staff in Ruom.onlinePlayers.filter { it.hasPermission("velocityvanish.admin.notify") && it != player }) {
staff.sendMessage(Message.UNVANISH_NOTIFY, TextReplacement("player", player.name))
staff.sendMessage(Message.UNVANISH_NOTIFY, player, TextReplacement("player", player.name))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PlayerJoinListener(
plugin.vanishManager.unVanish(player, sendJoinMessage = true, callPostEvent = true)
}

val joinMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.JOIN_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName)))
val joinMessage = Utils.getSerializedMessage(Settings.formatMessage(player, Message.JOIN_MESSAGE, player, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName)))
if (joinMessage.isNotBlank() && joinMessage.isNotEmpty()) {
Ruom.broadcast(joinMessage.component())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ object Settings {
}


fun formatMessage(player: Player, message: String, vararg replacements: TextReplacement): String {
fun formatMessage(message: String, placeholderTarget: Player, vararg replacements: TextReplacement): String {
var formattedMessage = formatMessage(message, *replacements)
if (DependencyManager.placeholderAPIHook.exists) {
formattedMessage = PlaceholderAPI.setPlaceholders(player, formattedMessage)
formattedMessage = PlaceholderAPI.setPlaceholders(placeholderTarget, formattedMessage)
}
return formattedMessage
}
Expand All @@ -153,8 +153,8 @@ object Settings {
return formattedMessage
}

fun formatMessage(player: Player, message: Message, vararg replacements: TextReplacement): String {
return formatMessage(player, getMessage(message), *replacements)
fun formatMessage(player: Player, message: Message, placeholderTarget: Player, vararg replacements: TextReplacement): String {
return formatMessage(getMessage(message), placeholderTarget, *replacements)
}

fun formatMessage(message: Message, vararg replacements: TextReplacement): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import ir.syrent.velocityvanish.spigot.storage.Settings
import ir.syrent.velocityvanish.spigot.utils.Utils.getSerializedMessage
import ir.syrent.velocityvanish.utils.TextReplacement
import ir.syrent.velocityvanish.utils.component
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

Expand All @@ -20,7 +18,11 @@ fun CommandSender.sendMessage(message: Message, vararg replacements: TextReplace
}

fun Player.sendMessage(message: Message, vararg replacements: TextReplacement) {
val formattedMessage = Settings.formatMessage(this, message, *replacements)
this.sendMessage(message, this, *replacements)
}

fun Player.sendMessage(message: Message, placeholderTarget: Player, vararg replacements: TextReplacement) {
val formattedMessage = Settings.formatMessage(this, message, placeholderTarget, *replacements)
if (formattedMessage.isBlank()) return

Settings.commandSound.let {
Expand All @@ -34,11 +36,11 @@ fun Player.sendMessage(message: Message, vararg replacements: TextReplacement) {
}

fun Player.sendMessageOnly(message: Message, vararg replacements: TextReplacement) {
val serializedMessage = getSerializedMessage(Settings.formatMessage(this, message, *replacements))
val serializedMessage = getSerializedMessage(Settings.formatMessage(this, message, this, *replacements))
AdventureApi.get().sender(this).sendMessage(serializedMessage.component())
}

fun Player.sendActionbar(message: Message, vararg replacements: TextReplacement) {
val serializedMessage = getSerializedMessage(Settings.formatMessage(this, message, *replacements))
val serializedMessage = getSerializedMessage(Settings.formatMessage(this, message, this, *replacements))
AdventureApi.get().sender(this).sendActionBar(serializedMessage.component())
}

0 comments on commit 72910fb

Please sign in to comment.