9
0
mirror of https://github.com/Auxilor/EcoJobs.git synced 2025-12-28 11:29:13 +00:00

Updated to libreforge 4

This commit is contained in:
Auxilor
2023-03-27 18:56:28 +01:00
parent 3fdafa0f7d
commit 7f331dd5dc
27 changed files with 421 additions and 534 deletions

View File

@@ -1,20 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
compileOnly 'net.kyori:adventure-api:4.10.1'
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6'
}
build.dependsOn publishToMavenLocal
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

View File

@@ -0,0 +1,22 @@
group = "com.willfp"
version = rootProject.version
dependencies {
compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
compileOnly("com.github.ben-manes.caffeine:caffeine:3.0.5")
compileOnly("com.willfp:ecomponent:1.3.0")
}
publishing {
publications {
register("maven", MavenPublication::class) {
from(components["java"])
}
}
}
tasks {
build {
dependsOn(publishToMavenLocal)
}
}

View File

@@ -8,28 +8,36 @@ import com.willfp.eco.util.toNiceString
import com.willfp.ecojobs.api.activeJobs
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.ecojobs.api.jobLimit
import com.willfp.ecojobs.commands.CommandEcojobs
import com.willfp.ecojobs.commands.CommandEcoJobs
import com.willfp.ecojobs.commands.CommandJobs
import com.willfp.ecojobs.jobs.JobLevelListener
import com.willfp.ecojobs.jobs.JobTriggerXPGainListener
import com.willfp.ecojobs.jobs.Jobs
import com.willfp.ecojobs.jobs.PriceHandler
import com.willfp.ecojobs.jobs.ResetOnQuitListener
import com.willfp.libreforge.LibReforgePlugin
import com.willfp.libreforge.SimpleProvidedHolder
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.ConfigCategory
import com.willfp.libreforge.registerHolderProvider
import org.bukkit.event.Listener
import java.util.regex.Pattern
class EcoJobsPlugin : LibReforgePlugin() {
class EcoJobsPlugin : LibreforgePlugin() {
init {
instance = this
registerHolderProvider { player ->
player.activeJobs.map { it.getLevel(player.getJobLevel(it)) }
player.activeJobs.map { it.getLevel(player.getJobLevel(it)) }.map {
SimpleProvidedHolder(it)
}
}
}
override fun handleEnableAdditional() {
this.copyConfigs("jobs")
override fun loadConfigCategories(): List<ConfigCategory> {
return listOf(
Jobs
)
}
override fun handleEnable() {
PlayerPlaceholder(
this,
"limit"
@@ -62,11 +70,13 @@ class EcoJobsPlugin : LibReforgePlugin() {
val place = placeString.toIntOrNull() ?: return@DynamicPlaceholder "Invalid place!"
val type = split.getOrNull(3) ?: return@DynamicPlaceholder "You must specify the top type!"
val topEntry = job.getTop(place)
return@DynamicPlaceholder when(type) {
return@DynamicPlaceholder when (type) {
"name" -> topEntry?.player?.savedDisplayName
?: this.langYml.getFormattedString("top.name-empty")
"amount" -> topEntry?.amount?.toNiceString()
?: this.langYml.getFormattedString("top.amount-empty")
else -> "Invalid type: $type! Available types: name/amount"
}
}.register()
@@ -74,7 +84,7 @@ class EcoJobsPlugin : LibReforgePlugin() {
override fun loadPluginCommands(): List<PluginCommand> {
return listOf(
CommandEcojobs(this),
CommandEcoJobs(this),
CommandJobs(this)
)
}
@@ -82,7 +92,6 @@ class EcoJobsPlugin : LibReforgePlugin() {
override fun loadListeners(): List<Listener> {
return listOf(
JobLevelListener(this),
JobTriggerXPGainListener,
ResetOnQuitListener,
PriceHandler
)

View File

@@ -0,0 +1,20 @@
package com.willfp.ecojobs.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand
import org.bukkit.command.CommandSender
class CommandEcoJobs(plugin: EcoPlugin) : PluginCommand(plugin, "ecojobs", "ecojobs.command.ecojobs", false) {
init {
this.addSubcommand(CommandReload(plugin))
.addSubcommand(CommandUnlock(plugin))
.addSubcommand(CommandGiveXP(plugin))
.addSubcommand(CommandReset(plugin))
}
override fun onExecute(sender: CommandSender, args: List<String>) {
sender.sendMessage(
plugin.langYml.getMessage("invalid-command")
)
}
}

View File

@@ -1,34 +0,0 @@
package com.willfp.ecojobs.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.ecojobs.jobs.Jobs
import com.willfp.libreforge.LibReforgePlugin
import com.willfp.libreforge.lrcdb.CommandExport
import com.willfp.libreforge.lrcdb.CommandImport
import com.willfp.libreforge.lrcdb.ExportableConfig
import org.bukkit.command.CommandSender
class CommandEcojobs(plugin: LibReforgePlugin) : PluginCommand(plugin, "ecojobs", "ecojobs.command.ecojobs", false) {
init {
this.addSubcommand(CommandReload(plugin))
.addSubcommand(CommandUnlock(plugin))
.addSubcommand(CommandGiveXP(plugin))
.addSubcommand(CommandReset(plugin))
.addSubcommand(CommandImport("jobs", plugin))
.addSubcommand(CommandExport(plugin) {
Jobs.values().map {
ExportableConfig(
it.id,
it.config
)
}
})
}
override fun onExecute(sender: CommandSender, args: List<String>) {
sender.sendMessage(
plugin.langYml.getMessage("invalid-command")
)
}
}

View File

@@ -4,7 +4,6 @@ import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import com.willfp.eco.core.data.profile
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.builder.ItemStackBuilder
import com.willfp.eco.core.placeholder.PlayerPlaceholder
@@ -12,42 +11,39 @@ import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
import com.willfp.eco.core.price.ConfiguredPrice
import com.willfp.eco.core.price.impl.PriceEconomy
import com.willfp.eco.core.registry.Registrable
import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.toNiceString
import com.willfp.ecojobs.EcoJobsPlugin
import com.willfp.ecojobs.api.activeJobs
import com.willfp.ecojobs.api.canJoinJob
import com.willfp.ecojobs.api.event.PlayerJobExpGainEvent
import com.willfp.ecojobs.api.event.PlayerJobJoinEvent
import com.willfp.ecojobs.api.event.PlayerJobLeaveEvent
import com.willfp.ecojobs.api.event.PlayerJobLevelUpEvent
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.ecojobs.api.getJobProgress
import com.willfp.ecojobs.api.getJobXP
import com.willfp.ecojobs.api.getJobXPRequired
import com.willfp.ecojobs.api.hasJobActive
import com.willfp.ecojobs.api.jobLimit
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.ConditionList
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.conditions.ConfiguredCondition
import com.willfp.libreforge.effects.ConfiguredEffect
import com.willfp.libreforge.counters.Counters
import com.willfp.libreforge.effects.EffectList
import com.willfp.libreforge.effects.Effects
import com.willfp.libreforge.events.TriggerPreProcessEvent
import com.willfp.libreforge.triggers.Counters
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.time.Duration
import java.util.DoubleSummaryStatistics
import java.util.Objects
import java.util.concurrent.TimeUnit
import kotlin.math.abs
import kotlin.math.max
class Job(
val id: String, val config: Config, private val plugin: EcoJobsPlugin
) {
val id: String,
val config: Config,
private val plugin: EcoJobsPlugin
) : Registrable {
private val topCache = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("leaderboard-cache-lifetime").toLong()))
.build<Int, LeaderboardCacheEntry?>()
@@ -85,8 +81,8 @@ class Job(
private val baseItem: ItemStack = Items.lookup(config.getString("icon")).item
private val effects: Set<ConfiguredEffect>
private val conditions: Set<ConfiguredCondition>
private val effects: EffectList
private val conditions: ConditionList
private val levels = Caffeine.newBuilder().build<Int, JobLevel>()
private val effectsDescription = Caffeine.newBuilder().build<Int, List<String>>()
@@ -106,7 +102,7 @@ class Job(
}
private val jobXpGains = config.getSubsections("xp-gain-methods").mapNotNull {
Counters.compile(it, "Job $id")
Counters.compile(it, ViolationContext(plugin, "Job $id"))
}
init {
@@ -116,13 +112,15 @@ class Job(
p.getJobLevel(this).toString()
})
effects = config.getSubsections("effects").mapNotNull {
Effects.compile(it, "Job $id")
}.toSet()
effects = Effects.compile(
config.getSubsections("effects"),
ViolationContext(plugin, "Job $id")
)
conditions = config.getSubsections("conditions").mapNotNull {
Conditions.compile(it, "Job $id")
}.toSet()
conditions = Conditions.compile(
config.getSubsections("conditions"),
ViolationContext(plugin, "Job $id")
)
for (string in config.getStrings("level-commands")) {
val split = string.split(":")
@@ -192,8 +190,16 @@ class Job(
}.register()
}
override fun onRegister() {
jobXpGains.forEach { it.bind(JobXPAccumulator(this)) }
}
override fun onRemove() {
jobXpGains.forEach { it.unbind() }
}
fun getLevel(level: Int): JobLevel = levels.get(level) {
JobLevel(this, it, effects, conditions)
JobLevel(plugin, this, it, effects, conditions)
}
private fun getLevelUpMessages(level: Int, whitespace: Int = 0): List<String> = levelUpMessages.get(level) {
@@ -334,7 +340,8 @@ class Job(
val base = baseItem.clone()
return ItemStackBuilder(base).setDisplayName(
plugin.configYml.getFormattedString("gui.job-info.active.name")
.replace("%level%", player.getJobLevel(this).toString()).replace("%level_numeral%", NumberUtils.toNumeral(player.getJobLevel(this))).replace("%job%", this.name)
.replace("%level%", player.getJobLevel(this).toString())
.replace("%level_numeral%", NumberUtils.toNumeral(player.getJobLevel(this))).replace("%job%", this.name)
).addLoreLines {
injectPlaceholdersInto(plugin.configYml.getStrings("gui.job-info.active.lore"), player)
}.build()
@@ -356,18 +363,18 @@ class Job(
}
}
fun getXP(event: TriggerPreProcessEvent): Double {
return jobXpGains.sumOf { it.getCount(event) }
}
fun getTop(place: Int): LeaderboardCacheEntry? {
return topCache.get(place) {
val players = Bukkit.getOfflinePlayers().sortedByDescending { it.getJobLevel(this) }
val target = players.getOrNull(place-1) ?: return@get null
val target = players.getOrNull(place - 1) ?: return@get null
return@get LeaderboardCacheEntry(target, target.getJobLevel(this))
}
}
override fun getID(): String {
return this.id
}
override fun equals(other: Any?): Boolean {
if (other !is Job) {
return false

View File

@@ -1,14 +1,16 @@
package com.willfp.ecojobs.jobs
import com.willfp.eco.core.EcoPlugin
import com.willfp.libreforge.Holder
import com.willfp.libreforge.conditions.ConfiguredCondition
import com.willfp.libreforge.effects.ConfiguredEffect
import com.willfp.libreforge.conditions.ConditionList
import com.willfp.libreforge.effects.EffectList
class JobLevel(
plugin: EcoPlugin,
val job: Job,
val level: Int,
override val effects: Set<ConfiguredEffect>,
override val conditions: Set<ConfiguredCondition>
): Holder {
override val id = "${job.id}_$level"
override val effects: EffectList,
override val conditions: ConditionList
) : Holder {
override val id = plugin.createNamespacedKey("${job.id}_$level")
}

View File

@@ -1,26 +0,0 @@
package com.willfp.ecojobs.jobs
import com.willfp.ecojobs.api.activeJobs
import com.willfp.ecojobs.api.giveJobExperience
import com.willfp.libreforge.events.TriggerPreProcessEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
object JobTriggerXPGainListener : Listener {
@EventHandler(ignoreCancelled = true)
fun handle(event: TriggerPreProcessEvent) {
val player = event.player
val jobs = event.player.activeJobs
for (job in jobs) {
val amount = job.getXP(event)
if (amount <= 0.0) {
continue
}
player.giveJobExperience(job, amount)
}
}
}

View File

@@ -0,0 +1,13 @@
package com.willfp.ecojobs.jobs
import com.willfp.ecojobs.api.giveJobExperience
import com.willfp.libreforge.counters.Accumulator
import org.bukkit.entity.Player
class JobXPAccumulator(
private val job: Job
) : Accumulator {
override fun accept(player: Player, count: Double) {
player.giveJobExperience(job, count)
}
}

View File

@@ -1,15 +1,17 @@
package com.willfp.ecojobs.jobs
import com.google.common.collect.BiMap
import com.google.common.collect.HashBiMap
import com.google.common.collect.ImmutableList
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.config.updating.ConfigUpdater
import com.willfp.eco.core.registry.Registry
import com.willfp.ecojobs.EcoJobsPlugin
import com.willfp.ecojobs.api.getJobLevel
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.ConfigCategory
import org.bukkit.OfflinePlayer
object Jobs {
private val BY_ID: BiMap<String, Job> = HashBiMap.create()
object Jobs : ConfigCategory("job", "jobs") {
private val registry = Registry<Job>()
/**
* Get all registered [Job]s.
@@ -18,7 +20,7 @@ object Jobs {
*/
@JvmStatic
fun values(): List<Job> {
return ImmutableList.copyOf(BY_ID.values)
return ImmutableList.copyOf(registry.values())
}
/**
@@ -29,45 +31,15 @@ object Jobs {
*/
@JvmStatic
fun getByID(name: String): Job? {
return BY_ID[name]
return registry[name]
}
/**
* Update all [Job]s.
*
* @param plugin Instance of EcoJobs.
*/
@ConfigUpdater
@JvmStatic
fun update(plugin: EcoJobsPlugin) {
for (job in values()) {
removeJob(job)
}
for ((id, jobConfig) in plugin.fetchConfigs("jobs")) {
addNewJob(Job(id, jobConfig, plugin))
}
override fun clear(plugin: LibreforgePlugin) {
registry.clear()
}
/**
* Add new [Job] to EcoJobs.
*
* @param job The [Job] to add.
*/
@JvmStatic
fun addNewJob(job: Job) {
BY_ID.remove(job.id)
BY_ID[job.id] = job
}
/**
* Remove [Job] from EcoJobs.
*
* @param job The [Job] to remove.
*/
@JvmStatic
fun removeJob(job: Job) {
BY_ID.remove(job.id)
override fun acceptConfig(plugin: LibreforgePlugin, id: String, config: Config) {
registry.register(Job(id, config, plugin as EcoJobsPlugin))
}
/**

View File

@@ -1,21 +0,0 @@
# Read more about chains: https://plugins.auxilor.io/effects/configuring-an-effect#effect-chains
chains:
- id: example_chain
effects:
- id: teleport
- id: potion_effect
args:
effect: blindness
level: 3
duration: 30
apply_to_player: true
- id: send_message
args:
message: "&fYou have been teleported!"
action_bar: true
- id: play_sound
args:
sound: entity_dragon_fireball_explode
pitch: 1.5
volume: 4

View File

@@ -278,49 +278,3 @@ level-up:
id: entity_player_levelup
# Pitch between 0.5 and 2
pitch: 1.3
cannot-afford:
in-actionbar: true
sound:
enabled: true
sound: "BLOCK_NOTE_BLOCK_PLING"
pitch: 0.5
cooldown:
in-actionbar: true
sound:
enabled: true
sound: "BLOCK_NOTE_BLOCK_PLING"
pitch: 0.5
cannot-afford-type:
in-actionbar: true
sound:
enabled: true
sound: "BLOCK_NOTE_BLOCK_PLING"
pitch: 0.5
cannot-afford-price:
in-actionbar: true
sound:
enabled: true
sound: "BLOCK_NOTE_BLOCK_PLING"
pitch: 0.5
point-names: # If you have point names that look ugly (eg g_souls) then you can map them to nice names to be shown to players.
example_point: "Nicely Formatted Point"
use-faster-move-trigger: true # Disable if you want move trigger to detect sub-1-block movements
raytrace-distance: 80 # The distance that alt_click should check for a location
leaderboard-cache-lifetime: 180 # How often will top placeholders update their cache (in seconds)
potions:
icon:
permanent: true
triggered: true
ambient:
permanent: false
triggered: true
particles:
permanent: false
triggered: true

View File

@@ -1,3 +1,8 @@
resource-id: 2857
bstats-id: 16394
color: "&#964B00"
environment:
- name: libreforge version
value: ${libreforgeVersion}
options:
resource-id: 2857
bstats-id: 16394
color: "&#964B00"

View File

@@ -4,18 +4,6 @@ messages:
not-player: "&cThis command must be run by a player"
invalid-command: "&cUnknown subcommand!"
reloaded: "Reloaded!"
cannot-afford: "&cYou can't afford to do this! &fCost: &a$$%cost%"
cannot-afford-type: "&cYou can't afford to do this! &fCost: &a%cost% %type%"
cannot-afford-price: "&cYou can't afford to do this! &fPrice: %price%"
on-cooldown: "&cThis effect is on cooldown! &fTime left: &a%seconds% seconds"
cannot-transmit: "&cYou can't transmit here!"
must-specify-lrcdb-id: "&cYou must specify the ID of the config to download! Not sure what this means? Go to &alrcdb.auxilor.io"
lrcdb-import-error: "&cError importing config: &f%message%"
lrcdb-import-success: "&fImported &a%name%&f! Reload the plugin to install it"
must-specify-config-name: "&cYou must specify the config name!"
invalid-config-name: "&cInvalid config name!"
lrcdb-export-error: "&cError exporting config: &f%message%"
lrcdb-export-success: "&fExported &a%name%&f! View it on &alrcdb.auxilor.io&f, or share your config ID: &f%id%"
needs-player: "&cYou must specify a player!"
gave-xp: "&fYou have given &a%xp% &fXP to %player%&f's %job%&f!"

View File

@@ -1,19 +0,0 @@
# Options for lrcdb (https://lrcdb.auxilor.io), a website to share configs
# with other server owners, so you can get more configs without making them
# yourself!
author: "Unknown Author" # The name attached to configs you export
# Options about automatically sharing configs you create
share-configs:
# If you want all your configs to automatically be publicly available,
# set this to true. This really helps out other users!
publicly: false
# If you don't want your configs to be usable to gather information about
# plugin usage or to improve the plugins in the future, disable this.
# Nothing identifying is shared.
enabled: true
# If you disable share-configs, you can still share select configs publicly
# with /ecojobs export <config>.

View File

@@ -0,0 +1,17 @@
name: ${pluginName}
version: ${version}
main: com.willfp.ecopets.EcoPetsPlugin
api-version: 1.19
dependencies:
- name: eco
required: true
bootstrap: false
- name: libreforge
required: false
bootstrap: false
load-after:
- name: eco
bootstrap: false

View File

@@ -1,25 +1,13 @@
name: EcoJobs
version: ${projectVersion}
main: com.willfp.ecojobs.EcoJobsPlugin
name: ${pluginName}
version: ${version}
main: com.willfp.ecopets.EcoPetsPlugin
api-version: 1.17
authors: [ Auxilor ]
website: willfp.com
depend:
- eco
softdepend:
- AureliumSkills
- Vault
- mcMMO
- Jobs
- TMMobcoins
- EcoEnchants
- EcoBosses
- Talismans
- EcoArmor
- EcoItems
- Boosters
- EcoSkills
- Reforges
- libreforge
commands:
ecojobs:
description: Base Command
@@ -49,8 +37,6 @@ permissions:
ecojobs.command.join: true
ecojobs.command.leave: true
ecojobs.command.reset: true
ecojobs.command.import: true
ecojobs.command.export: true
ecojobs.command.reload:
description: Allows reloading the config
@@ -70,12 +56,6 @@ permissions:
ecojobs.command.reset:
description: Allows the use of /ecojobs reset.
default: op
ecojobs.command.import:
description: Allows the use of /ecojobs import.
default: op
ecojobs.command.export:
description: Allows the use of /ecojobs export.
default: op
ecojobs.command.join:
description: Allows the use of /jobs join.
default: true