Initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
|
||||
compileOnly 'com.willfp:EcoEnchants:8.2.0'
|
||||
compileOnly 'com.willfp:EcoSkills:1.2.4'
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.willfp.boosters
|
||||
|
||||
import com.willfp.boosters.boosters.Booster
|
||||
import com.willfp.boosters.boosters.Boosters
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.Server
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
private var active: Booster? = null
|
||||
private val plugin = BoostersPlugin.instance
|
||||
|
||||
var Server.activeBooster: Booster?
|
||||
get() {
|
||||
return active
|
||||
}
|
||||
set(value) {
|
||||
active = value
|
||||
}
|
||||
|
||||
val OfflinePlayer.boosters: List<Booster>
|
||||
get() {
|
||||
val found = mutableListOf<Booster>()
|
||||
val section = plugin.dataYml.getSubsectionOrNull("${this.uniqueId}")
|
||||
|
||||
for (key in (section?.getKeys(false) ?: emptyList())) {
|
||||
val booster = Boosters.getById(key) ?: continue
|
||||
val amount = section?.getIntOrNull(key) ?: continue
|
||||
|
||||
for (i in 0 until amount) {
|
||||
found.add(booster)
|
||||
}
|
||||
}
|
||||
|
||||
return found
|
||||
}
|
||||
|
||||
fun OfflinePlayer.getAmountOfBooster(booster: Booster): Int {
|
||||
return plugin.dataYml.getIntOrNull("${this.uniqueId}.${booster.id}") ?: 0
|
||||
}
|
||||
|
||||
|
||||
fun OfflinePlayer.setAmountOfBooster(booster: Booster, amount: Int) {
|
||||
plugin.dataYml.set("${this.uniqueId}.${booster.id}", amount)
|
||||
}
|
||||
|
||||
fun Player.activateBooster(booster: Booster): Boolean {
|
||||
val amount = this.getAmountOfBooster(booster)
|
||||
|
||||
if (amount <= 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
setAmountOfBooster(booster, amount - 1)
|
||||
|
||||
for (activationMessage in booster.getActivationMessages(this)) {
|
||||
Bukkit.broadcastMessage(activationMessage)
|
||||
}
|
||||
|
||||
plugin.scheduler.runLater ({
|
||||
for (expiryMessage in booster.getExpiryMessages()) {
|
||||
Bukkit.broadcastMessage(expiryMessage)
|
||||
}
|
||||
Bukkit.getServer().activeBooster = null
|
||||
}, booster.duration.toLong())
|
||||
|
||||
active = booster
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.willfp.boosters
|
||||
|
||||
import com.willfp.boosters.commands.CommandBoosters
|
||||
import com.willfp.boosters.config.DataYml
|
||||
import com.willfp.boosters.data.SaveHandler
|
||||
import com.willfp.boosters.data.SaveHandler.Companion.save
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import org.bukkit.event.Listener
|
||||
import java.io.IOException
|
||||
|
||||
class BoostersPlugin : EcoPlugin() {
|
||||
val dataYml: DataYml
|
||||
override fun handleReload() {
|
||||
save(this)
|
||||
scheduler.runTimer(SaveHandler.Runnable(this), 20000, 20000)
|
||||
}
|
||||
|
||||
override fun handleDisable() {
|
||||
try {
|
||||
dataYml.save()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadListeners(): List<Listener> {
|
||||
return listOf(
|
||||
)
|
||||
}
|
||||
|
||||
override fun loadPluginCommands(): List<PluginCommand> {
|
||||
return listOf(
|
||||
CommandBoosters(this)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getMinimumEcoVersion(): String {
|
||||
return "6.7.0"
|
||||
}
|
||||
|
||||
init {
|
||||
dataYml = DataYml(this)
|
||||
instance = this
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var instance: BoostersPlugin
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.willfp.boosters.boosters
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
abstract class Booster(
|
||||
protected val plugin: BoostersPlugin,
|
||||
val id: String
|
||||
): Listener {
|
||||
abstract val duration: Int
|
||||
|
||||
init {
|
||||
register()
|
||||
}
|
||||
|
||||
private fun register() {
|
||||
Boosters.registerNewBooster(this)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Booster) {
|
||||
return false
|
||||
}
|
||||
|
||||
return other.id == this.id
|
||||
}
|
||||
|
||||
fun getActivationMessages(player: Player): List<String> {
|
||||
val messages = mutableListOf<String>()
|
||||
|
||||
for (string in this.plugin.configYml.getStrings(
|
||||
"messages.${this.id}.activation",
|
||||
true,
|
||||
StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
|
||||
)) {
|
||||
messages.add(string.replace("%player%", player.displayName))
|
||||
}
|
||||
|
||||
return messages
|
||||
}
|
||||
|
||||
fun getExpiryMessages(): List<String> {
|
||||
return this.plugin.configYml.getStrings("messages.${this.id}.expiry")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.boosters.boosters
|
||||
|
||||
import com.willfp.boosters.boosters.boosters.Booster15SellMultiplier
|
||||
import com.willfp.boosters.boosters.boosters.Booster2SellMultiplier
|
||||
import com.willfp.boosters.boosters.boosters.BoosterSkillXP
|
||||
|
||||
object Boosters {
|
||||
private val byId = mutableMapOf<String, Booster>()
|
||||
|
||||
val SKILL_XP = BoosterSkillXP()
|
||||
val SELL_MULTIPLIER_LOW = Booster15SellMultiplier()
|
||||
val SELL_MULTIPLIER_HIGH = Booster2SellMultiplier()
|
||||
|
||||
fun getById(id: String): Booster? {
|
||||
return byId[id.lowercase()]
|
||||
}
|
||||
|
||||
fun registerNewBooster(booster: Booster) {
|
||||
byId[booster.id] = booster
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.willfp.boosters.boosters.boosters
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import com.willfp.boosters.activeBooster
|
||||
import com.willfp.boosters.boosters.Booster
|
||||
import net.brcdev.shopgui.event.ShopPreTransactionEvent
|
||||
import net.brcdev.shopgui.shop.ShopManager
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
|
||||
class Booster15SellMultiplier: Booster(
|
||||
BoostersPlugin.instance,
|
||||
"1.5sell_multiplier"
|
||||
) {
|
||||
override val duration = 72000
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
fun handle(event: ShopPreTransactionEvent) {
|
||||
if (Bukkit.getServer().activeBooster != this) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.shopAction == ShopManager.ShopAction.BUY) {
|
||||
return
|
||||
}
|
||||
|
||||
event.price *= 1.5
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.willfp.boosters.boosters.boosters
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import com.willfp.boosters.activeBooster
|
||||
import com.willfp.boosters.boosters.Booster
|
||||
import net.brcdev.shopgui.event.ShopPreTransactionEvent
|
||||
import net.brcdev.shopgui.shop.ShopManager
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
|
||||
class Booster2SellMultiplier: Booster(
|
||||
BoostersPlugin.instance,
|
||||
"2sell_multiplier"
|
||||
) {
|
||||
override val duration = 72000
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
fun handle(event: ShopPreTransactionEvent) {
|
||||
if (Bukkit.getServer().activeBooster != this) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.shopAction == ShopManager.ShopAction.BUY) {
|
||||
return
|
||||
}
|
||||
|
||||
event.price *= 2
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.willfp.boosters.boosters.boosters
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import com.willfp.boosters.activeBooster
|
||||
import com.willfp.boosters.boosters.Booster
|
||||
import com.willfp.ecoskills.api.PlayerSkillExpGainEvent
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
|
||||
class BoosterSkillXP: Booster(
|
||||
BoostersPlugin.instance,
|
||||
"skill_xp"
|
||||
) {
|
||||
override val duration = 72000
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
fun onGainSkillXP(event: PlayerSkillExpGainEvent) {
|
||||
if (Bukkit.getServer().activeBooster != this) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
event.amount *= 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.boosters.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.boosters.gui.SkillGUI
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class CommandBoosters(plugin: EcoPlugin) :
|
||||
PluginCommand(
|
||||
plugin,
|
||||
"boosters",
|
||||
"boosters.command.boosters",
|
||||
true
|
||||
) {
|
||||
|
||||
init {
|
||||
this.addSubcommand(CommandGive(plugin))
|
||||
.addSubcommand(CommandReload(plugin))
|
||||
}
|
||||
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender: CommandSender, _: List<String> ->
|
||||
if (sender !is Player) {
|
||||
sender.sendMessage(this.plugin.langYml.getMessage("not-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
SkillGUI.getHomeMenu().open(sender)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.willfp.boosters.commands
|
||||
|
||||
import com.google.common.math.Stats
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.TabCompleteHandler
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import com.willfp.boosters.getStatLevel
|
||||
import com.willfp.boosters.giveSkillExperience
|
||||
import com.willfp.boosters.setStatLevel
|
||||
import com.willfp.boosters.skills.Skill
|
||||
import com.willfp.boosters.skills.Skills
|
||||
import com.willfp.boosters.stats.Stat
|
||||
import com.willfp.boosters.stats.Stats
|
||||
import com.willfp.boosters.util.TabCompleteHelper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.util.StringUtil
|
||||
|
||||
|
||||
class CommandGive(plugin: EcoPlugin) :
|
||||
Subcommand(
|
||||
plugin,
|
||||
"give",
|
||||
"boosters.command.give",
|
||||
false
|
||||
) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender: CommandSender, args: List<String> ->
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
if (args.size == 1) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-booster"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
val player = Bukkit.getPlayer(args[0])
|
||||
if (player == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
val obj = Skills.getByID(args[1].lowercase()) ?: Stats.getByID(args[1].lowercase())
|
||||
|
||||
if (obj == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-booster"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
val amount = args[2].toIntOrNull()
|
||||
|
||||
if (amount == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
if (obj is Skill) {
|
||||
player.giveSkillExperience(obj, amount.toDouble())
|
||||
player.sendMessage(
|
||||
this.plugin.langYml.getMessage("gave-skill-xp")
|
||||
.replace("%player%", player.name)
|
||||
.replace("%amount%", amount.toString())
|
||||
.replace("%skill%", obj.name)
|
||||
)
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
if (obj is Stat) {
|
||||
player.setStatLevel(obj, player.getStatLevel(obj) + amount)
|
||||
sender.sendMessage(
|
||||
this.plugin.langYml.getMessage("gave-stat")
|
||||
.replace("%player%", player.name)
|
||||
.replace("%amount%", amount.toString())
|
||||
.replace("%stat%", obj.name)
|
||||
)
|
||||
return@CommandHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTabCompleter(): TabCompleteHandler {
|
||||
return TabCompleteHandler { _, args ->
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()),
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
TabCompleteHelper.SKILL_NAMES union TabCompleteHelper.STAT_NAMES,
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
|
||||
if (args.size == 3) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[2],
|
||||
TabCompleteHelper.AMOUNTS,
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
}
|
||||
|
||||
return@TabCompleteHandler emptyList<String>()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.boosters.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.CommandHandler
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import org.bukkit.command.CommandSender
|
||||
|
||||
class CommandReload(plugin: EcoPlugin) :
|
||||
Subcommand(
|
||||
plugin,
|
||||
"reload",
|
||||
"boosters.command.reload",
|
||||
false
|
||||
) {
|
||||
override fun getHandler(): CommandHandler {
|
||||
return CommandHandler { sender: CommandSender, _: List<String> ->
|
||||
plugin.reload()
|
||||
sender.sendMessage(plugin.langYml.getMessage("reloaded"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.boosters.config
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.yaml.YamlBaseConfig
|
||||
|
||||
class DataYml(
|
||||
plugin: EcoPlugin
|
||||
): YamlBaseConfig(
|
||||
"data",
|
||||
false,
|
||||
plugin
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.willfp.boosters.data
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import org.bukkit.Bukkit
|
||||
|
||||
class SaveHandler {
|
||||
companion object {
|
||||
fun save(plugin: BoostersPlugin) {
|
||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
return
|
||||
}
|
||||
if (plugin.configYml.getBool("log-autosaves")) {
|
||||
plugin.logger.info("Auto-Saving player data!")
|
||||
}
|
||||
plugin.dataYml.save()
|
||||
if (plugin.configYml.getBool("log-autosaves")) {
|
||||
plugin.logger.info("Saved data!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Runnable(
|
||||
private val plugin: BoostersPlugin
|
||||
) : java.lang.Runnable {
|
||||
override fun run() {
|
||||
save(plugin)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# Boosters
|
||||
# by Auxilor
|
||||
#
|
||||
|
||||
log-autosaves: true # If auto-save messages should be sent to console
|
||||
|
||||
messages:
|
||||
1.5sell_multiplier:
|
||||
activation:
|
||||
- ""
|
||||
- "%player%&f has activated a &a1.5x Sell Multiplier Booster&f!"
|
||||
- "&fThis booster will last an hour, be sure to thank them!"
|
||||
- ""
|
||||
expiry:
|
||||
- ""
|
||||
- "&fThe &a1.5x Sell Multiplier Booster&f has ended"
|
||||
- "&fGet another one here: "
|
||||
- ""
|
||||
2sell_multiplier:
|
||||
activation:
|
||||
- ""
|
||||
- "%player%&f has activated a &a2x Sell Multiplier Booster&f!"
|
||||
- "&fThis booster will last an hour, be sure to thank them!"
|
||||
- ""
|
||||
expiry:
|
||||
- ""
|
||||
- "&fThe &a2x Sell Multiplier Booster&f has ended"
|
||||
- "&fGet another one here: "
|
||||
- ""
|
||||
skill_xp:
|
||||
activation:
|
||||
- ""
|
||||
- "%player%&f has activated a &a2x Skill XP Booster&f!"
|
||||
- "&fThis booster will last an hour, be sure to thank them!"
|
||||
- ""
|
||||
expiry:
|
||||
- ""
|
||||
- "&fThe &a2x Skill XP Booster&f has ended"
|
||||
- "&fGet another one here: "
|
||||
- ""
|
||||
@@ -0,0 +1 @@
|
||||
# Don't edit this file - it's for internal storage only
|
||||
@@ -0,0 +1,11 @@
|
||||
messages:
|
||||
prefix: "&a&lBoosters&r &8» &r"
|
||||
no-permission: "&cYou don't have permission to do this!"
|
||||
not-player: "&cThis command must be run by a player"
|
||||
invalid-command: "&cUnknown subcommand!"
|
||||
reloaded: "Reloaded!"
|
||||
requires-player: "&cYou must specify a player!"
|
||||
invalid-player: "&cInvalid player!"
|
||||
requires-booster: "&cYou must specify a booster!"
|
||||
invalid-booster: "&cInvalid booster!"
|
||||
gave-booster: "Gave %player% %booster%!"
|
||||
@@ -0,0 +1,45 @@
|
||||
name: Boosters
|
||||
version: ${projectVersion}
|
||||
main: com.willfp.boosters.BoostersPlugin
|
||||
api-version: 1.17
|
||||
authors: [ Auxilor ]
|
||||
website: willfp.com
|
||||
load: POSTWORLD
|
||||
depend:
|
||||
- eco
|
||||
- PlaceholderAPI
|
||||
- EcoSkills
|
||||
- ShopGUIPlus
|
||||
libraries:
|
||||
- org.jetbrains.kotlin:kotlin-stdlib:1.5.21
|
||||
|
||||
commands:
|
||||
boosters:
|
||||
description: Base Command
|
||||
permission: boosters.command.boosters
|
||||
aliases:
|
||||
- boost
|
||||
|
||||
permissions:
|
||||
boosters.*:
|
||||
description: All boosters permissions
|
||||
default: op
|
||||
children:
|
||||
boosters.command.*: true
|
||||
boosters.command.*:
|
||||
description: All commands
|
||||
default: op
|
||||
children:
|
||||
boosters.command.reload: true
|
||||
boosters.command.give: true
|
||||
boosters.command.boosters: true
|
||||
|
||||
boosters.command.reload:
|
||||
description: Allows reloading the config
|
||||
default: op
|
||||
boosters.command.boosters:
|
||||
description: Allows the use of /boosters.
|
||||
default: true
|
||||
boosters.command.give:
|
||||
description: Allows the use of /boosters give.
|
||||
default: op
|
||||
Reference in New Issue
Block a user