Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customizable reminder message types #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/main/kotlin/me/clip/voteparty/conf/sections/VoteSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ internal object VoteSettings : SettingsHolder
"Note: A FULL reboot is required for this to take effect if changed after the plugin has been loaded.")
val REMINDER_INTERVAL_SECONDS: Property<Int> = newProperty("voting.reminder_interval_seconds", 600)

@JvmField
@Comment("What message type to send the reminder as? Options are: chat, actionbar, title, bossbar.",
"If the value is missing or is invalid, chat is used.")
val REMINDER_MESSAGE_TYPE: Property<String> = newProperty("voting.reminder_message_type", "chat")

@JvmField
@Comment("What percentage of the bossbar should be filled? The value should be between 0.0 and 1.0.",
"Defaults to 1.0 which represents a full bossbar.", "This is only used if the reminder message type is set to bossbar.")
val REMINDER_BOSSBAR_FILL: Property<Double> = newProperty("voting.reminder_bossbar_fill", 1.0)

@JvmField
@Comment("What color should the bossbar be? Options are: pink, blue, red, green, yellow, purple, white.",
"Defaults to purple.", "This is only used if the reminder message type is set to bossbar.")
val REMINDER_BOSSBAR_COLOR: Property<String> = newProperty("voting.reminder_bossbar_color", "purple")

@JvmField
@Comment("What overlay should the bossbar have? Options are: progress, notched_6, notched_10, notched_12, notched_20.",
"Defaults to progress.", "This is only used if the reminder message type is set to bossbar.")
val REMINDER_BOSSBAR_OVERLAY: Property<String> = newProperty("voting.reminder_bossbar_overlay", "progress")

@JvmField
@Comment("How long should the bossbar stay on the screen? (in ticks, 1 second = 20 ticks)",
"Defaults to 3 seconds.", "This is only used if the reminder message type is set to bossbar.")
val REMINDER_BOSSBAR_STAY_TIME: Property<Int> = newProperty("voting.reminder_bossbar_stay_time", 60)

@JvmField
@Comment("How long should the title take to fade in? (in ticks, 1 second = 20 ticks)",
"Defaults to half a second.", "This is only used if the reminder message type is set to title.")
val REMINDER_TITLE_FADE_IN: Property<Int> = newProperty("voting.reminder_title_fade_in", 10)

@JvmField
@Comment("How long should the title stay on the screen? (in ticks, 1 second = 20 ticks)",
"Defaults to 3 and a half seconds.", "This is only used if the reminder message type is set to title.")
val REMINDER_TITLE_STAY: Property<Int> = newProperty("voting.reminder_title_stay", 70)

@JvmField
@Comment("How long should the title take to fade out? (in ticks, 1 second = 20 ticks)",
"Defaults to a second.", "This is only used if the reminder message type is set to title.")
val REMINDER_TITLE_FADE_OUT: Property<Int> = newProperty("voting.reminder_title_fade_out", 20)

@JvmField
@Comment("If a player's inventory is full when voting, do you want to send the vote to a /vote claim?")
val CLAIMABLE_IF_FULL: Property<Boolean> = newProperty("voting.claim_if_full", true)
Expand Down
61 changes: 55 additions & 6 deletions src/main/kotlin/me/clip/voteparty/exte/funcs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import co.aikar.commands.ACFUtil
import co.aikar.commands.CommandIssuer
import co.aikar.locales.MessageKeyProvider
import me.clip.placeholderapi.PlaceholderAPI
import me.clip.voteparty.VoteParty
import me.clip.voteparty.base.Addon
import me.clip.voteparty.conf.objects.Command
import me.clip.voteparty.conf.sections.PluginSettings
import me.clip.voteparty.conf.sections.VoteSettings
import net.kyori.adventure.bossbar.BossBar
import net.kyori.adventure.identity.Identity
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import net.kyori.adventure.title.Title
import net.kyori.adventure.util.Ticks
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
Expand All @@ -36,18 +41,52 @@ internal fun formMessage(player: OfflinePlayer, message: String): String
return color(PlaceholderAPI.setPlaceholders(player, message))
}

internal fun Addon.sendMessage(receiver: CommandIssuer, message: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray())
private fun parseMessage(party: VoteParty, receiver: CommandIssuer, message: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray()): String
{
var msg = receiver.manager.locales.getMessage(receiver, message)

if (replacements.isNotEmpty() && replacements.size % 2 == 0)
{
msg = ACFUtil.replaceStrings(msg, *replacements.map(Any::toString).toTypedArray())
}

val result = formMessage(Bukkit.getOfflinePlayer(placeholderTarget?.uniqueId ?: receiver.uniqueId), (party.conf().getProperty(PluginSettings.PREFIX) ?: PREFIX) + msg)

party.audiences().sender(receiver.getIssuer()).sendMessage(Identity.nil(), serializer.deserialize(result))

return formMessage(Bukkit.getOfflinePlayer(placeholderTarget?.uniqueId ?: receiver.uniqueId), (party.conf().getProperty(PluginSettings.PREFIX) ?: PREFIX) + msg)
}

internal fun Addon.sendActionBar(receiver: CommandIssuer, message: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray())
{
val msg = parseMessage(party, receiver, message, placeholderTarget, *replacements)
party.audiences().sender(receiver.getIssuer()).sendActionBar(serializer.deserialize(msg))
}

internal fun Addon.sendTitle(receiver: CommandIssuer, title: MessageKeyProvider, subtitle: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray())
{
val titleMsg = parseMessage(party, receiver, title, placeholderTarget, *replacements)
val subtitleMsg = parseMessage(party, receiver, subtitle, placeholderTarget, *replacements)
val fadeIn = Ticks.duration(party.conf().getProperty(VoteSettings.REMINDER_TITLE_FADE_IN).toLong())
val stay = Ticks.duration(party.conf().getProperty(VoteSettings.REMINDER_TITLE_STAY).toLong())
val fadeOut = Ticks.duration(party.conf().getProperty(VoteSettings.REMINDER_TITLE_FADE_OUT).toLong())
val times = Title.Times.times(fadeIn, stay, fadeOut)
party.audiences().sender(receiver.getIssuer()).showTitle(Title.title(serializer.deserialize(titleMsg), serializer.deserialize(subtitleMsg), times))
}

internal fun Addon.sendBossBar(receiver: CommandIssuer, message: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray())
{
val msg = parseMessage(party, receiver, message, placeholderTarget, *replacements)
val progress = getZeroToOne(party.conf().getProperty(VoteSettings.REMINDER_BOSSBAR_FILL))
val color = BossBar.Color.NAMES.valueOr(party.conf().getProperty(VoteSettings.REMINDER_BOSSBAR_COLOR).lowercase(), BossBar.Color.PURPLE)
val overlay = BossBar.Overlay.NAMES.valueOr(party.conf().getProperty(VoteSettings.REMINDER_BOSSBAR_OVERLAY).lowercase(), BossBar.Overlay.PROGRESS)
val bossBar = BossBar.bossBar(serializer.deserialize(msg), progress, color, overlay)
party.audiences().sender(receiver.getIssuer()).showBossBar(bossBar)
plugin.runTaskLater(party.conf().getProperty(VoteSettings.REMINDER_BOSSBAR_STAY_TIME).toLong()){
party.audiences().sender(receiver.getIssuer()).hideBossBar(bossBar)
}
}

internal fun Addon.sendMessage(receiver: CommandIssuer, message: MessageKeyProvider, placeholderTarget: OfflinePlayer? = null, vararg replacements: Any = emptyArray())
{
val msg = parseMessage(party, receiver, message, placeholderTarget, *replacements)
party.audiences().sender(receiver.getIssuer()).sendMessage(Identity.nil(), serializer.deserialize(msg))
}

internal fun msgAsString(issuer: CommandIssuer, key: MessageKeyProvider): String
Expand Down Expand Up @@ -108,3 +147,13 @@ internal var ItemMeta.name: String
{
setDisplayName(color(value))
}

private fun getZeroToOne(value: Double): Float
{
return when
{
value < 0.0 -> 0.0f
value > 1.0 -> 1.0f
else -> value.toFloat()
}
}
10 changes: 9 additions & 1 deletion src/main/kotlin/me/clip/voteparty/handler/VotesHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import me.clip.voteparty.conf.sections.PartySettings
import me.clip.voteparty.conf.sections.VoteData
import me.clip.voteparty.conf.sections.VoteSettings
import me.clip.voteparty.exte.formMessage
import me.clip.voteparty.exte.sendActionBar
import me.clip.voteparty.exte.sendBossBar
import me.clip.voteparty.exte.sendMessage
import me.clip.voteparty.exte.sendTitle
import me.clip.voteparty.exte.takeRandomly
import me.clip.voteparty.leaderboard.LeaderboardType
import me.clip.voteparty.messages.Messages
Expand Down Expand Up @@ -274,7 +277,12 @@ class VotesHandler(override val plugin: VotePartyPlugin) : Addon, State
}

players.forEach {
sendMessage(party.manager().getCommandIssuer(it), Messages.VOTES__REMINDER)
when(party.conf().getProperty(VoteSettings.REMINDER_MESSAGE_TYPE)) {
"actionbar" -> sendActionBar(party.manager().getCommandIssuer(it), Messages.VOTES__REMINDER)
"bossbar" -> sendBossBar(party.manager().getCommandIssuer(it), Messages.VOTES__REMINDER)
"title" -> sendTitle(party.manager().getCommandIssuer(it), Messages.VOTES__REMINDER, Messages.VOTES__REMINDER_SUBTITLE)
else -> sendMessage(party.manager().getCommandIssuer(it), Messages.VOTES__REMINDER)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/me/clip/voteparty/messages/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class Messages : MessageKeyProvider
VOTES__ADDED_TO_PLAYER,
VOTES__INVENTORY_FULL,
VOTES__REMINDER,
VOTES__REMINDER_SUBTITLE,

CRATE__CRATE_GIVEN,
CRATE__CRATE_RECEIVED,
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/de-DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ votes:
added-to-player: "&fDu hast {count} Stimmen für %player_name% gegeben!"
inventory-full: "&fDein Inventar scheint voll zu sein! Wir haben deine Vote Belohnung in dein Rucksack gepackt! Mache /vp claim, sobald dein Inventar nicht voll ist!"
reminder: "&fDon't forget to vote for our server!"
# The subtitle only works when the reminder message type is set to title.
reminder-subtitle: "&fYou can vote by using &d/vote&f!"
crate:
crate-given: "&fDu hast &d%player_name% &fvote bekommen oder erstellt!"
crate-received: "Du hast ein Vote erstellt!"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ votes:
added-to-player: "&fYou've given {count} votes to %player_name%!"
inventory-full: "&fYour inventory seems to be full! We've put this vote in your claimables! Do /vp claim once your inventory isn't full!"
reminder: "&fDon't forget to vote for our server!"
# The subtitle only works when the reminder message type is set to title.
reminder-subtitle: "&fYou can vote by using &d/vote&f!"
crate:
crate-given: "&fYou've given &d%player_name% &fvote crate(s)!"
crate-received: "&fYou've received a vote crate!"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ votes:
added-to-player: "&fVous avez donné {count} votes à %player_name%!"
inventory-full: "&fYour inventory seems to be full! We've put this vote in your claimables! Do /vp claim once your inventory isn't full!"
reminder: "&fDon't forget to vote for our server!"
# The subtitle only works when the reminder message type is set to title.
reminder-subtitle: "&fYou can vote by using &d/vote&f!"
crate:
crate-given: "&fVous avez donné à &d%player_name% &f une vote crate(s)!"
crate-received: "&fVous avez reçu une caisse de vote !"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/nl-NL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ votes:
added-to-player: "&fJe hebt {count} stemmen aan %player_name% gegeven!"
inventory-full: "&fJou inventaris is vol! We hebben deze stem in je claimables geplaats! Doe /vp claim wanneer je inventaris niet vol is!"
reminder: "&fDon't forget to vote for our server!"
# The subtitle only works when the reminder message type is set to title.
reminder-subtitle: "&fYou can vote by using &d/vote&f!"
crate:
crate-given: "&fJe hebt &d%player_name% &fvote crate(s) gegeven!"
crate-received: "&fJe hebt een vote crate ontvangen!"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/languages/sv-SE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ votes:
added-to-player: "&fDu har gett {count} röster till %player_name%!"
inventory-full: "&fYour inventory seems to be full! We've put this vote in your claimables! Do /vp claim once your inventory isn't full!"
reminder: "&fDon't forget to vote for our server!"
# The subtitle only works when the reminder message type is set to title.
reminder-subtitle: "&fYou can vote by using &d/vote&f!"
crate:
crate-given: "&fDu har gett &d%player_name% röstlådor!"
crate-received: "&fDu har fått en röstlåda!"
Expand Down
Loading