Skip to content

Commit

Permalink
hook AttributePlus and add many functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SoutheyLeo committed Nov 5, 2021
1 parent 6e89df0 commit 13a83c1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
package com.faithl.bukkit.faithllevel.internal.command

import com.faithl.bukkit.faithllevel.FaithlLevel
import com.faithl.bukkit.faithllevel.api.FaithlLevelAPI
import com.faithl.bukkit.faithllevel.internal.command.impl.*
import com.faithl.bukkit.faithllevel.internal.conf.Loader
import com.faithl.bukkit.faithllevel.internal.level.Level
import com.faithl.bukkit.faithllevel.internal.level.data.ExpDataManager
import org.bukkit.Bukkit
import org.bukkit.Bukkit.getPlayerExact
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.ProxyPlayer
import taboolib.common.platform.command.CommandBody
import taboolib.common.platform.command.CommandHeader
import taboolib.common.platform.command.mainCommand
import taboolib.common.platform.command.subCommand
import taboolib.common.platform.function.adaptCommandSender
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.onlinePlayers
import taboolib.common.platform.function.pluginVersion
import taboolib.common5.Coerce
import taboolib.module.chat.TellrawJson
import taboolib.module.lang.Language
import taboolib.module.lang.sendLang
import taboolib.platform.util.asLangText
import taboolib.platform.util.sendLang


@CommandHeader(name = "faithllevel", aliases = ["fl","flevel","level"], permission = "FaithlLevel.access")
object CommandHandler {
@CommandBody
val boot = CommandBoot.command
val booster = CommandBooster.command

@CommandBody
val status = CommandStatus.command
Expand Down Expand Up @@ -103,7 +87,7 @@ object CommandHandler {
displayArg("set", sender.asLangText("Command-Set-Description"))
displayArg("take", sender.asLangText("Command-Take-Description"))
if (FaithlLevel.ap)
displayArg("boot", sender.asLangText("Command-Boot-Description"))
displayArg("booster", sender.asLangText("Command-Booster-Description"))
displayArg("status", sender.asLangText("Command-Status-Description"))
displayArg("reload", sender.asLangText("Command-Reload-Description"))
proxySender.sendMessage("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.faithl.bukkit.faithllevel.internal.command.impl

import com.faithl.bukkit.faithllevel.api.FaithlLevelAPI
import com.faithl.bukkit.faithllevel.internal.level.Level
import com.faithl.bukkit.faithllevel.internal.level.data.ExpDataManager
import com.faithl.bukkit.faithllevel.util.getBoot
import com.faithl.bukkit.faithllevel.util.setBoot
import com.faithl.bukkit.faithllevel.util.setBooster
import org.bukkit.Bukkit
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.ProxyPlayer
Expand All @@ -13,7 +11,7 @@ import taboolib.common.platform.function.onlinePlayers
import taboolib.common5.Coerce
import taboolib.module.lang.sendLang

object CommandBoot {
object CommandBooster {
val command = subCommand {
execute<ProxyCommandSender>{ sender, _, _ ->
sender.sendLang("Command-Boot-Error")
Expand All @@ -32,7 +30,7 @@ object CommandBoot {
val level = FaithlLevelAPI.getLevelData(context.argument(-1)) ?: return@execute
val value = Coerce.toDouble(argument)/100
val player = Bukkit.getPlayerExact(sender.name) ?: return@execute
player.setBoot(level,value)
player.setBooster(level,value)
sender.sendLang("Command-Boot-Info", level.name!!,sender.name,"${argument}%")
}
//value
Expand All @@ -48,7 +46,7 @@ object CommandBoot {
val target = Bukkit.getPlayerExact(context.argument(-1)) ?: return@execute
val level = FaithlLevelAPI.getLevelData(context.argument(-2)) ?: return@execute
val value = Coerce.toDouble(argument)/100
target.setBoot(level,value)
target.setBooster(level,value)
sender.sendLang("Command-Boot-Info", level.name!!,target.name,"${argument}%")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.faithl.bukkit.faithllevel.internal.command.impl
import com.faithl.bukkit.faithllevel.api.FaithlLevelAPI
import com.faithl.bukkit.faithllevel.internal.level.Level
import com.faithl.bukkit.faithllevel.internal.level.data.ExpDataManager
import com.faithl.bukkit.faithllevel.util.getBoot
import org.bukkit.Bukkit
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.ProxyPlayer
Expand All @@ -17,7 +16,7 @@ object CommandStatus {
for (levelSystem in Level.levels){
val playerData: ExpDataManager = FaithlLevelAPI.getPlayerData(sender.cast(),levelSystem)
sender.sendLang("Command-Status-Info",
levelSystem.name!!,sender.name,playerData.getDisplay(),playerData.exp,playerData.getMaxExp(),playerData.getTotalBoot())
levelSystem.name!!,sender.name,playerData.getDisplay(),playerData.exp,playerData.getMaxExp(),playerData.getTotalBooster())
}
}
dynamic {
Expand All @@ -29,7 +28,7 @@ object CommandStatus {
for (levelSystem in Level.levels){
val playerData: ExpDataManager = FaithlLevelAPI.getPlayerData(target,levelSystem)
sender.sendLang("Command-Status-Info",
levelSystem.name!!,target.name,playerData.getDisplay(),playerData.exp,playerData.getMaxExp(),playerData.getTotalBoot())
levelSystem.name!!,target.name,playerData.getDisplay(),playerData.exp,playerData.getMaxExp(),playerData.getTotalBooster())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Level(private val configurationSection:ConfigurationSection) {
val messages: ConfigurationSection? = configurationSection.getConfigurationSection("Messages")
val permission: MutableList<String>? = configurationSection.getStringList("Permissions")
val ap: ConfigurationSection? = configurationSection.getConfigurationSection("AttributePlus")
val permissionBoot: MutableList<String>? = configurationSection.getStringList("Exp-Permission-Boot")
val permissionBooster: MutableList<String>? = configurationSection.getStringList("Exp-Permission-Booster")
init {
levels.add(this)
requireNotNull(key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class ExpDataManager(val player: Player, val levelData: Level) {
}

fun getTotalAddExp(addExpAmount: Int): Int {
return addExpAmount.times(1 + getTotalBoot()).roundToInt()
return addExpAmount.times(1 + getTotalBooster()).roundToInt()
}

fun getTotalBoot(): Double {
fun getTotalBooster(): Double {
var boot = 0.0
if (FaithlLevel.ap && levelData.ap?.getString("Exp-Boot-Attribute")!=null){
boot += AttributeAPI.getAttrData(player).getRandomValue(levelData.ap.getString("Exp-Boot-Attribute")).toDouble()/100
}
boot += getPermissionBoot()
boot += player.getBoot(levelData)
boot += getPermissionBooster()
boot += player.getBooster(levelData)
return boot
}

Expand Down Expand Up @@ -202,8 +202,8 @@ class ExpDataManager(val player: Player, val levelData: Level) {
return display.replaceWithOrder(this.level).colored()
}

private fun getPermissionBoot(): Double {
val permissionBootList = levelData.permissionBoot ?: return 0.0
private fun getPermissionBooster(): Double {
val permissionBootList = levelData.permissionBooster ?: return 0.0
if (this.getMaxLevel() < level) {
return 0.0
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/faithl/bukkit/faithllevel/util/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import taboolib.expansion.getDataContainer
import taboolib.expansion.releaseDataContainer
import taboolib.expansion.setupDataContainer

fun Player.getBoot(level:Level):Double {
fun Player.getBooster(level:Level):Double {
releaseDataContainer()
setupDataContainer()
return getDataContainer()["${level.key}_boot"]?.toDoubleOrNull() ?: return 0.0
Expand All @@ -25,7 +25,7 @@ fun Player.getFLevel(level:Level): Int {
return Coerce.toInteger(getDataContainer()["${level.key}_level"])
}

fun Player.setBoot(level:Level,value:Double) {
fun Player.setBooster(level:Level,value:Double) {
releaseDataContainer()
setupDataContainer()
getDataContainer()["${level.key}_boot"]=value
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Command-Set-Error: '&8[&3FaithlLevel&8][&cERROR&8] &r错误的用法, 请使用&
Command-Set-Info: '&8[&3FaithlLevel&8][&b{0}&8] &r设置 &b{1}&r 玩家等级为: &b{2}&r 级。'
Command-Status-Description: '查看玩家信息'
Command-Status-Info: '&8[&3FaithlLevel&8][&b{0}&8] &r玩家 &b{1} &r当前信息: &b{2}&8 - &r[&b{3}&8/&3{4}&r], 经验加成: &b{5}&r。'
Command-Boot-Description: '玩家经验加成设置'
Command-Boot-Info: '&8[&3FaithlLevel&8][&b{0}&8] &r玩家 &b{1} &r的经验加成已设置为 &b{2}&r。'
Command-Boot-Error: '&8[&3FaithlLevel&8][&cERROR&8] &r错误的用法, 请使用&b/faithllevel boot [Level] [玩家] [数值]&r。'
Command-Booster-Description: '玩家经验加成设置'
Command-Booster-Info: '&8[&3FaithlLevel&8][&b{0}&8] &r玩家 &b{1} &r的经验加成已设置为 &b{2}&r。'
Command-Booster-Error: '&8[&3FaithlLevel&8][&cERROR&8] &r错误的用法, 请使用&b/faithllevel boot [Level] [玩家] [数值]&r。'

Level-Loader-Loaded: '&8[&3FaithlLevel&8][&bINFO&8] &b{0} &r个等级已加载 &8({1} ms)'
Level-Loader-Failed: '&8[&3FaithlLevel&8][&cERROR&8] &b{0} &r等级加载失败, 原因:{1}'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/levels/示例主等级.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MainLevel:
- "10:50"
- "100:100"
#权限经验加成,若玩家含有该权限则获得加成,单位%
Exp-Permission-Boot:
Exp-Permission-Booster:
- "5:faithl.access:100"
Permissions:
#填写default为不需权限
Expand Down

0 comments on commit 13a83c1

Please sign in to comment.