9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-03 14:22:17 +00:00

Merge pull request #132 from 0ft3n/master

Farming skill will now properly support bamboo and sugar cane
This commit is contained in:
Will FP
2023-01-27 11:36:59 +00:00
committed by GitHub
8 changed files with 100 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ allprojects {
maven { url 'https://repo.codemc.io/repository/maven-public/' }
maven { url 'https://repo.dmulloy2.net/repository/public/' }
maven { url 'https://repo.essentialsx.net/releases/' }
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
}
jar {
@@ -49,6 +50,7 @@ allprojects {
compileOnly 'com.willfp:eco:6.44.0'
implementation 'com.willfp:libreforge:3.128.0'
implementation 'org.joml:joml:1.10.4'
compileOnly 'me.clip:placeholderapi:2.11.2'
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
compileOnly 'com.github.LegameMc:EnchantGui-API:1.0'

View File

@@ -19,6 +19,7 @@ import com.willfp.ecoskills.effects.Effect;
import com.willfp.ecoskills.effects.Effects;
import com.willfp.ecoskills.integrations.EcoEnchantsEnchantingLeveller;
import com.willfp.ecoskills.integrations.enchantgui.EnchantGuiHandler;
import com.willfp.ecoskills.placeholders.EcoSkillsTopExpansion;
import com.willfp.ecoskills.skills.CustomSkillTriggerXPGainListener;
import com.willfp.ecoskills.skills.Skill;
import com.willfp.ecoskills.skills.SkillDisplayListener;
@@ -149,7 +150,8 @@ public class EcoSkillsPlugin extends LibReforgePlugin {
public List<IntegrationLoader> loadAdditionalIntegrations() {
return List.of(
new IntegrationLoader("EcoEnchants", () -> this.getEventManager().registerListener(new EcoEnchantsEnchantingLeveller(this))),
new IntegrationLoader("EnchantGui", () -> this.getEventManager().registerListener(new EnchantGuiHandler()))
new IntegrationLoader("EnchantGui", () -> this.getEventManager().registerListener(new EnchantGuiHandler())),
new IntegrationLoader("PlaceholderAPI", () -> new EcoSkillsTopExpansion(this).register())
);
}
}

View File

@@ -22,7 +22,7 @@ class CommandTop(plugin: EcoPlugin) :
val page = args.firstOrNull()?.toIntOrNull() ?: 1
val top = LeaderboardHandler.getPage(page)
val messages = plugin.langYml.getStrings("top")
val messages = plugin.langYml.getStrings("top.format")
val lines = mutableListOf<String>()
val useDisplayName = plugin.configYml.getBool("commands.top.use-display-name")

View File

@@ -0,0 +1,53 @@
package com.willfp.ecoskills.placeholders
import com.willfp.eco.util.savedDisplayName
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.skills.Skills
import me.clip.placeholderapi.expansion.PlaceholderExpansion
import org.bukkit.OfflinePlayer
class EcoSkillsTopExpansion(val plugin: EcoSkillsPlugin): PlaceholderExpansion() {
/**
* The placeholder identifier of this expansion. May not contain %,
* {} or _
*
* @return placeholder identifier that is associated with this expansion
*/
override fun getIdentifier(): String {
return "ecoskillstop"
}
/**
* The author of this expansion
*
* @return name of the author for this expansion
*/
override fun getAuthor(): String {
return "_OfTeN_"
}
/**
* The version of this expansion
*
* @return current version of this expansion
*/
override fun getVersion(): String {
return "1.0.0"
}
override fun onRequest(player: OfflinePlayer?, params: String): String? {
val args = params.split("_")
val skill = Skills.getByID(args.firstOrNull()?.lowercase() ?: return "Invalid skill")
val place = args.getOrNull(1)?.toIntOrNull() ?: return "Invalid place (must be an integer)"
return when (args.lastOrNull() ?: return "Invalid type: ${args.lastOrNull()}. Must be name/amount") {
"name" -> skill?.getTop(place)?.player?.savedDisplayName ?: plugin.langYml.getFormattedString(
"top.name-empty"
)
"amount" -> skill?.getTop(place)?.amount?.toString() ?: plugin.langYml.getFormattedString(
"top.amount-empty"
)
else -> null
}
}
}

View File

@@ -1,5 +1,6 @@
package com.willfp.ecoskills.skills
import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
@@ -24,14 +25,19 @@ import com.willfp.ecoskills.stats.Stats
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.NamespacedKey
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import java.time.Duration
abstract class Skill @JvmOverloads constructor(
val id: String,
forceConfig: Config? = null
) : Listener {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val leaderBoardCache: Cache<Int, LeaderboardCacheEntry?> = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofSeconds(plugin.configYml.getInt("cache-expire-after").toLong()))
.build()
val key: NamespacedKey = plugin.namespacedKeyFactory.create(id)
@@ -240,6 +246,17 @@ abstract class Skill @JvmOverloads constructor(
return levels
}
fun getTop(place: Int): LeaderboardCacheEntry? {
return leaderBoardCache.get(place) {
val top = Bukkit.getOfflinePlayers()
.sortedByDescending { it.getSkillLevel(this) }.getOrNull(place - 1)
if (top == null) {
null
} else LeaderboardCacheEntry(top, top.getSkillLevel(this))
}
}
fun getRewardsMessages(player: Player?, level: Int): List<String> {
val raw = messagesCache.get(level) {
val parentSection = this.config.getSubsection("rewards.chat-messages")
@@ -351,3 +368,5 @@ abstract class Skill @JvmOverloads constructor(
}
}
}
data class LeaderboardCacheEntry(val player: OfflinePlayer, val amount: Int)

View File

@@ -4,6 +4,7 @@ import com.willfp.eco.util.BlockUtils
import com.willfp.ecoskills.giveSkillExperience
import com.willfp.ecoskills.skills.Skill
import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.block.data.Ageable
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
@@ -14,6 +15,10 @@ class SkillFarming : Skill(
"farming"
) {
private val rewards: MutableMap<Material, Double>
private val stackedCrops = listOf(
Material.SUGAR_CANE,
Material.BAMBOO
)
init {
rewards = EnumMap(org.bukkit.Material::class.java)
@@ -60,6 +65,16 @@ class SkillFarming : Skill(
val toGive = rewards[type] ?: return
player.giveSkillExperience(this, toGive)
var amount = 1
if (type in stackedCrops) {
var current = event.block.getRelative(BlockFace.UP)
while (current.type == type) {
amount++
current = current.getRelative(BlockFace.UP)
}
}
player.giveSkillExperience(this, toGive*amount)
}
}

View File

@@ -549,6 +549,7 @@ point-names: # If you have point names that look ugly (eg g_souls) then you can
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
cache-expire-after: 180 # The amount of seconds to cache a player's leaderboard stats for
potions:
icon:

View File

@@ -42,8 +42,11 @@ line-wrap-color: "&8"
top-line-format: "%rank%. %playername% - %level%"
top:
- "---- Skills Leaderboard ----"
- "%lines%"
format:
- "---- Skills Leaderboard ----"
- "%lines%"
name-empty: "&cEmpty"
amount-empty: "&0"
menu:
title: "Your Skills"