Skip to content

Commit

Permalink
Release/v5.2 (#1745)
Browse files Browse the repository at this point in the history
Merging the latest release into the main branch.

---------

Co-authored-by: Ren Binden <[email protected]>
Co-authored-by: Donut <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2023
1 parent 709ec27 commit 03174cc
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 117 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.dansplugins"
version = "5.1.4"
version = "5.2.0"

def repoUsername = ""
def repoPassword = ""
Expand Down
169 changes: 114 additions & 55 deletions src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.dansplugins.factionsystem.law.MfLawService
import com.dansplugins.factionsystem.legacy.MfLegacyDataMigrator
import com.dansplugins.factionsystem.listener.AreaEffectCloudApplyListener
import com.dansplugins.factionsystem.listener.AsyncPlayerChatListener
import com.dansplugins.factionsystem.listener.AsyncPlayerChatPreviewListener
import com.dansplugins.factionsystem.listener.AsyncPlayerPreLoginListener
import com.dansplugins.factionsystem.listener.BlockBreakListener
import com.dansplugins.factionsystem.listener.BlockExplodeListener
Expand All @@ -57,6 +56,7 @@ import com.dansplugins.factionsystem.listener.EntityExplodeListener
import com.dansplugins.factionsystem.listener.InventoryMoveItemListener
import com.dansplugins.factionsystem.listener.LingeringPotionSplashListener
import com.dansplugins.factionsystem.listener.PlayerDeathListener
import com.dansplugins.factionsystem.listener.PlayerInteractEntityListener
import com.dansplugins.factionsystem.listener.PlayerInteractListener
import com.dansplugins.factionsystem.listener.PlayerJoinListener
import com.dansplugins.factionsystem.listener.PlayerMoveListener
Expand Down Expand Up @@ -95,7 +95,6 @@ import org.bstats.charts.SimplePie
import org.bukkit.NamespacedKey
import org.bukkit.boss.KeyedBossBar
import org.bukkit.entity.Player
import org.bukkit.event.player.AsyncPlayerChatEvent
import org.bukkit.plugin.java.JavaPlugin
import org.flywaydb.core.Flyway
import org.jooq.SQLDialect
Expand Down Expand Up @@ -141,12 +140,6 @@ class MedievalFactions : JavaPlugin() {
saveConfig()

language = Language(this, config.getString("language") ?: "en-US")
val metrics = Metrics(this, 8929)
metrics.addCustomChart(
SimplePie("language_used") {
config.getString("language")
}
)

Class.forName("org.h2.Driver")
val hikariConfig = HikariConfig()
Expand Down Expand Up @@ -214,7 +207,7 @@ class MedievalFactions : JavaPlugin() {
val duelService = MfDuelService(this, duelRepository, duelInviteRepository)
val potionService = MfPotionService(this)
val teleportService = MfTeleportService(this)
val dynmapService = if (server.pluginManager.getPlugin("dynmap") != null) {
val dynmapService = if (server.pluginManager.getPlugin("dynmap") != null && config.getBoolean("dynmap.enableDynmapIntegration")) {
MfDynmapService(this)
} else {
null
Expand All @@ -238,6 +231,64 @@ class MedievalFactions : JavaPlugin() {
)
setupRpkLockService()

val metrics = Metrics(this, 8929)
metrics.addCustomChart(
SimplePie("language_used") {
config.getString("language")
}
)
metrics.addCustomChart(
SimplePie("database_dialect") {
config.getString("database.dialect")
}
)
metrics.addCustomChart(
SimplePie("average_claims") {
factionService.factions
.map {
claimService.getClaims(it.id).size
}
.average().roundToInt().toString()
}
)
metrics.addCustomChart(
SimplePie("total_claims") {
factionService.factions.sumOf {
claimService.getClaims(it.id).size
}.toString()
}
)
metrics.addCustomChart(
SimplePie("initial_power") {
config.getDouble("players.initialPower").toString()
}
)
metrics.addCustomChart(
SimplePie("max_power") {
config.getDouble("players.maxPower").toString()
}
)
metrics.addCustomChart(
SimplePie("hours_to_reach_max_power") {
config.getDouble("players.hoursToReachMaxPower").toString()
}
)
metrics.addCustomChart(
SimplePie("hours_to_reach_min_power") {
config.getDouble("players.hoursToReachMinPower").toString()
}
)
metrics.addCustomChart(
SimplePie("limit_land") {
config.getBoolean("factions.limitLand").toString()
}
)
metrics.addCustomChart(
SimplePie("allow_neutrality") {
config.getBoolean("factions.allowNeutrality").toString()
}
)

if (config.getBoolean("migrateMf4")) {
migrator.migrate()
config.set("migrateMf4", null)
Expand Down Expand Up @@ -275,11 +326,9 @@ class MedievalFactions : JavaPlugin() {
PlayerMoveListener(this),
PlayerQuitListener(this),
PlayerTeleportListener(this),
PotionSplashListener(this)
PotionSplashListener(this),
PlayerInteractEntityListener(this)
)
if (isChatPreviewEventAvailable()) {
registerListeners(AsyncPlayerChatPreviewListener(this))
}

getCommand("faction")?.setExecutor(MfFactionCommand(this))
getCommand("lock")?.setExecutor(MfLockCommand(this))
Expand All @@ -297,42 +346,12 @@ class MedievalFactions : JavaPlugin() {
server.scheduler.runTaskAsynchronously(
this,
Runnable {
val originalOnlinePlayerPower =
onlineMfPlayerIds.associateWith { playerService.getPlayer(it)?.power ?: initialPower }
playerService.updatePlayerPower(onlineMfPlayerIds).onFailure {
logger.log(SEVERE, "Failed to update player power: ${it.reason.message}", it.reason.cause)
return@Runnable
}
val newOnlinePlayerPower =
onlineMfPlayerIds.associateWith { playerService.getPlayer(it)?.power ?: initialPower }
server.scheduler.runTask(
this,
Runnable {
onlinePlayers.forEach { onlinePlayer ->
val playerId = MfPlayerId.fromBukkitPlayer(onlinePlayer)
val newPower = newOnlinePlayerPower[playerId] ?: initialPower
val originalPower = originalOnlinePlayerPower[playerId] ?: initialPower
val powerIncrease = floor(newPower).roundToInt() - floor(originalPower).roundToInt()
if (powerIncrease > 0) {
onlinePlayer.sendMessage("$GREEN${language["PowerIncreased", powerIncrease.toString()]}")
}
}
}
onPowerCycle(
onlineMfPlayerIds,
initialPower,
onlinePlayers,
disbandZeroPowerFactions
)
if (disbandZeroPowerFactions) {
factionService.factions.forEach { faction ->
if (faction.power <= 0.0) {
faction.sendMessage(
language["FactionDisbandedZeroPowerNotificationTitle"],
language["FactionDisbandedZeroPowerNotificationBody"]
)
factionService.delete(faction.id).onFailure {
logger.log(SEVERE, "Failed to delete faction: ${it.reason.message}", it.reason.cause)
return@Runnable
}
}
}
}
}
)
}, (15 - (LocalTime.now().minute % 15)) * 60 * 20L, 18000L)
Expand Down Expand Up @@ -442,6 +461,53 @@ class MedievalFactions : JavaPlugin() {
}
}

internal fun onPowerCycle(
onlineMfPlayerIds: List<MfPlayerId>,
initialPower: Double,
onlinePlayers: Collection<Player>,
disbandZeroPowerFactions: Boolean
) {
val playerService = services.playerService
val factionService = services.factionService

val originalOnlinePlayerPower =
onlineMfPlayerIds.associateWith { playerService.getPlayer(it)?.power ?: initialPower }
playerService.updatePlayerPower(onlineMfPlayerIds).onFailure {
logger.log(SEVERE, "Failed to update player power: ${it.reason.message}", it.reason.cause)
return
}
val newOnlinePlayerPower =
onlineMfPlayerIds.associateWith { playerService.getPlayer(it)?.power ?: initialPower }
server.scheduler.runTask(
this,
Runnable {
onlinePlayers.forEach { onlinePlayer ->
val playerId = MfPlayerId.fromBukkitPlayer(onlinePlayer)
val newPower = newOnlinePlayerPower[playerId] ?: initialPower
val originalPower = originalOnlinePlayerPower[playerId] ?: initialPower
val powerIncrease = floor(newPower).roundToInt() - floor(originalPower).roundToInt()
if (powerIncrease > 0) {
onlinePlayer.sendMessage("$GREEN${language["PowerIncreased", powerIncrease.toString()]}")
}
}
}
)
if (disbandZeroPowerFactions) {
factionService.factions.forEach { faction ->
if (faction.power <= 0.0) {
faction.sendMessage(
language["FactionDisbandedZeroPowerNotificationTitle"],
language["FactionDisbandedZeroPowerNotificationBody"]
)
factionService.delete(faction.id).onFailure {
logger.log(SEVERE, "Failed to delete faction: ${it.reason.message}", it.reason.cause)
return
}
}
}
}
}

private fun setupNotificationService(): MfNotificationService = when {
server.pluginManager.getPlugin("Mailboxes") != null -> MailboxesNotificationService(this)
server.pluginManager.getPlugin("rpk-notification-lib-bukkit") != null -> RpkNotificationService(this)
Expand All @@ -453,11 +519,4 @@ class MedievalFactions : JavaPlugin() {
MfRpkLockService(this)
}
}

private fun isChatPreviewEventAvailable() = try {
val previewClass = Class.forName("org.bukkit.event.player.AsyncPlayerChatPreviewEvent")
AsyncPlayerChatEvent::class.java.isAssignableFrom(previewClass)
} catch (exception: ClassNotFoundException) {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class MfClaimService(private val plugin: MedievalFactions, private val repositor
if (claimFaction.flags[plugin.flags.liegeChainCanInteractWithLand] && lieges.contains(playerFaction.id)) return true
val allies = relationshipService.getRelationships(claim.factionId, MfFactionRelationshipType.ALLY).map { it.targetId }
if (claimFaction.flags[plugin.flags.alliesCanInteractWithLand] && allies.contains(playerFaction.id)) return true
val atWar = relationshipService.getRelationships(claim.factionId, MfFactionRelationshipType.AT_WAR).map { it.targetId }
if (plugin.config.getBoolean("pvp.enableWartimeBlockDestruction") && atWar.contains(playerFaction.id)) return true
return false
}

Expand Down Expand Up @@ -92,9 +94,16 @@ class MfClaimService(private val plugin: MedievalFactions, private val repositor
Runnable {
players.forEach { player ->
val title = "${ChatColor.of(faction.flags[plugin.flags.color])}${faction.name}"
val subtitle = "${ChatColor.of(faction.flags[plugin.flags.color])}${faction.description}"
if (plugin.config.getBoolean("factions.titleTerritoryIndicator")) {
player.resetTitle()
player.sendTitle(title, null, 10, 70, 20)
player.sendTitle(
title,
subtitle,
plugin.config.getInt("factions.titleTerritoryFadeInLength"),
plugin.config.getInt("factions.titleTerritoryDuration"),
plugin.config.getInt("factions.titleTerritoryFadeOutLength")
)
}
if (plugin.config.getBoolean("factions.actionBarTerritoryIndicator")) {
player.spigot().sendMessage(ACTION_BAR, *TextComponent.fromLegacyText(title))
Expand Down Expand Up @@ -138,7 +147,13 @@ class MfClaimService(private val plugin: MedievalFactions, private val repositor
"${ChatColor.of(plugin.config.getString("wilderness.color"))}${plugin.language["Wilderness"]}"
if (plugin.config.getBoolean("factions.titleTerritoryIndicator")) {
player.resetTitle()
player.sendTitle(title, null, 10, 70, 20)
player.sendTitle(
title,
null,
plugin.config.getInt("factions.titleTerritoryFadeInLength"),
plugin.config.getInt("factions.titleTerritoryDuration"),
plugin.config.getInt("factions.titleTerritoryFadeOutLength")
)
}
if (plugin.config.getBoolean("factions.actionBarTerritoryIndicator")) {
player.spigot().sendMessage(ACTION_BAR, *TextComponent.fromLegacyText(title))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ class MfFactionCommand(private val plugin: MedievalFactions) : CommandExecutor,
in devAliases -> factionDevCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
// Backwards compatibility:
in claimAutoAliases -> {
sender.sendMessage("${RED}Command deprecated, use \"/mf claim auto\" instead")
factionClaimAutoCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
sender.sendMessage("${RED}${plugin.language["DeprecationWarningAutoclaim"]}")
false
}
in claimFillAliases -> {
sender.sendMessage("${RED}Command deprecated, use \"/mf claim fill\" instead")
factionClaimFillCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
sender.sendMessage("${RED}${plugin.language["DeprecationWarningFillclaim"]}")
false
}
in claimCheckAliases -> {
sender.sendMessage("${RED}Command deprecated, use \"/mf claim check\" instead")
factionClaimCheckCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
sender.sendMessage("${RED}${plugin.language["DeprecationWarningCheckclaim"]}")
false
}
else -> {
sender.sendMessage("$AQUA${plugin.language["MedievalFactionsTitle", plugin.description.version]}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class MfFactionAddMemberCommand(private val plugin: MedievalFactions) : CommandE
return true
}

val maxMembers = plugin.config.getInt("factions.maxMembers")
if (maxMembers > 0 && targetFaction.members.size >= maxMembers) {
sender.sendMessage("${ChatColor.RED}${plugin.language["CommandFactionAddMemberTargetFactionFull"]}")
return true
}

// add member to faction
val updatedFaction = factionService.save(
targetFaction.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import org.bukkit.command.TabCompleter
class MfFactionDevCommand(private val plugin: MedievalFactions) : CommandExecutor, TabCompleter {

private val factionDevGenerateCommand = MfFactionDevGenerateCommand(plugin)
private val factionDevPowerCycleCommand = MfFactionDevPowerCycleCommand(plugin)

private val generateAliases = listOf("generate")
private val powerCycleAliases = listOf("powercycle")

private val subcommands = generateAliases
private val subcommands = generateAliases + powerCycleAliases

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
return when (args.firstOrNull()?.lowercase()) {
in generateAliases -> factionDevGenerateCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
in powerCycleAliases -> factionDevPowerCycleCommand.onCommand(sender, command, label, args.drop(1).toTypedArray())
else -> {
sender.sendMessage("${RED}Usage: /faction dev [generate]")
sender.sendMessage("${RED}Usage: /faction dev [generate|powercycle]")
true
}
}
Expand All @@ -35,6 +38,7 @@ class MfFactionDevCommand(private val plugin: MedievalFactions) : CommandExecuto
args.size == 1 -> subcommands.filter { it.startsWith(args[0].lowercase()) }
else -> when (args.first().lowercase()) {
in generateAliases -> factionDevGenerateCommand.onTabComplete(sender, command, label, args.drop(1).toTypedArray())
in powerCycleAliases -> factionDevPowerCycleCommand.onTabComplete(sender, command, label, args.drop(1).toTypedArray())
else -> emptyList()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dansplugins.factionsystem.command.faction.dev

import com.dansplugins.factionsystem.MedievalFactions
import com.dansplugins.factionsystem.player.MfPlayerId
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter

class MfFactionDevPowerCycleCommand(private val plugin: MedievalFactions) : CommandExecutor, TabCompleter {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
val onlinePlayers = plugin.server.onlinePlayers
val onlineMfPlayerIds = onlinePlayers.map(MfPlayerId.Companion::fromBukkitPlayer)
val disbandZeroPowerFactions = plugin.config.getBoolean("factions.zeroPowerFactionsGetDisbanded")
val initialPower = plugin.config.getDouble("players.initialPower")
plugin.server.scheduler.runTaskAsynchronously(
plugin,
Runnable {
plugin.onPowerCycle(
onlineMfPlayerIds,
initialPower,
onlinePlayers,
disbandZeroPowerFactions
)
}
)
return true
}

override fun onTabComplete(
sender: CommandSender,
command: Command,
label: String,
args: Array<out String>
) = emptyList<String>()
}
Loading

0 comments on commit 03174cc

Please sign in to comment.