Skip to content

Commit

Permalink
Merge pull request #21
Browse files Browse the repository at this point in the history
Add PlaceholderAPI support.
  • Loading branch information
Syrent authored Nov 5, 2022
2 parents 28efba3 + 0f31289 commit 389fd65
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 8 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ repositories {
maven {
url "https://repo.dmulloy2.net/repository/public/"
}

// PlaceholderAPI
maven {
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
}

dependencies {
compileOnly 'com.velocitypowered:velocity-api:3.1.1'
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
compileOnly 'me.clip:placeholderapi:2.11.2'

compileOnly files("libs/SayanChat-2.8.3.jar")
compileOnly files('libs/ProCosmetics-13.7.jar')
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=3.3.1
version=3.4.0
plugin-name=VelocityVanish
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class VanishCommand(
) : PluginCommand("vanish", "velocityvanish.command.vanish", true) {

init {
addSubcommand(ReloadSubcommand())
this.register()
addSubcommand(ReloadSubcommand())
}

override fun onExecute(sender: CommandSender, args: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ object DependencyManager {
private set
var proCosmeticsHook: ProCosmeticsHook
private set
var placeholderAPIHook: PlaceholderAPIHook
private set

init {
ProtocolLibHook("ProtocolLib").apply {
Expand All @@ -26,6 +28,10 @@ object DependencyManager {
this.register()
proCosmeticsHook = this
}
PlaceholderAPIHook("PlaceholderAPI").apply {
this.register()
placeholderAPIHook = this
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ir.syrent.velocityvanish.spigot.hook

class PlaceholderAPIHook constructor(name: String) : Dependency(name) {

override fun features(): List<String> {
return mutableListOf(
"Access to all placeholders in all plugin messages."
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PostUnVanishListener(
plugin.vanishedNames.remove(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, false)

val joinMessage = Settings.formatMessage(Message.JOIN_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName))
val joinMessage = Settings.formatMessage(player, Message.JOIN_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName))
if (joinMessage.isNotBlank() && joinMessage.isNotEmpty() && event.sendJoinMessage) {
Ruom.broadcast(joinMessage.component())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PostVanishListener(
plugin.vanishedNames.add(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)

val quitMessage = Settings.formatMessage(Message.QUIT_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName))
val quitMessage = Settings.formatMessage(player, Message.QUIT_MESSAGE, TextReplacement("player", player.name), TextReplacement("play_displayname", player.displayName))
if (quitMessage.isNotBlank() && quitMessage.isNotEmpty() && event.sendQuitMessage) {
Ruom.broadcast(quitMessage.component())
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ir/syrent/velocityvanish/spigot/storage/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package ir.syrent.velocityvanish.spigot.storage

import com.cryptomorin.xseries.XSound
import ir.syrent.velocityvanish.spigot.configuration.YamlConfig
import ir.syrent.velocityvanish.spigot.hook.DependencyManager
import ir.syrent.velocityvanish.spigot.hook.PlaceholderAPIHook
import ir.syrent.velocityvanish.spigot.ruom.Ruom
import ir.syrent.velocityvanish.spigot.ruom.adventure.AdventureApi
import ir.syrent.velocityvanish.utils.TextReplacement
import ir.syrent.velocityvanish.utils.component
import me.clip.placeholderapi.PlaceholderAPI
import org.bukkit.Sound
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Player
import java.io.File
import java.nio.file.Files
import java.time.LocalDate
Expand Down Expand Up @@ -95,6 +99,15 @@ object Settings {
}


fun formatMessage(player: Player, message: String, vararg replacements: TextReplacement): String {
var formattedMessage = formatMessage(message, *replacements)
if (DependencyManager.placeholderAPIHook.exists) {
formattedMessage = PlaceholderAPI.setPlaceholders(player, formattedMessage)
}
return formattedMessage
}


fun formatMessage(message: String, vararg replacements: TextReplacement): String {
var formattedMessage = message
.replace("\$prefix", getMessage(Message.PREFIX))
Expand All @@ -107,6 +120,10 @@ object Settings {
return formattedMessage
}

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

fun formatMessage(message: Message, vararg replacements: TextReplacement): String {
return formatMessage(getMessage(message), *replacements)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ fun CommandSender.sendMessage(message: Message, vararg replacements: TextReplace
}

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

this.playSound(this.location, Settings.commandSound, 1f, 1f)
AdventureApi.get().sender(this).sendMessage(formattedMessage.component())
}

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

fun Player.sendActionbar(message: Message, vararg replacements: TextReplacement) {
AdventureApi.get().sender(this).sendActionBar(Settings.formatMessage(message, *replacements).component())
AdventureApi.get().sender(this).sendActionBar(Settings.formatMessage(this, message, *replacements).component())
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ softdepend:
- 'ProtocolLib'
- 'ProCosmetics'
- 'SayanChat'
- 'PlaceholderAPI'
commands:
vanish:
aliases:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":"velocityvanish","name":"VelocityVanish","version":"3.3.1","description":"Vanish plugin for velocity servers","url":"syrent.ir","authors":["Syrent"],"dependencies":[],"main":"ir.syrent.velocityvanish.velocity.VelocityVanish"}
{"id":"velocityvanish","name":"VelocityVanish","version":"3.4.0","description":"Vanish plugin for velocity servers","url":"syrent.ir","authors":["Syrent"],"dependencies":[],"main":"ir.syrent.velocityvanish.velocity.VelocityVanish"}

0 comments on commit 389fd65

Please sign in to comment.