Finished up
This commit is contained in:
@@ -5,6 +5,7 @@ import com.willfp.boosters.boosters.Boosters
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.Server
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
private var active: Booster? = null
|
||||
@@ -66,6 +67,15 @@ fun Player.activateBooster(booster: Booster): Boolean {
|
||||
|
||||
active = booster
|
||||
|
||||
for (player in Bukkit.getOnlinePlayers()) {
|
||||
player.playSound(
|
||||
player.location,
|
||||
Sound.UI_TOAST_CHALLENGE_COMPLETE,
|
||||
2f,
|
||||
0.9f
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.boosters
|
||||
|
||||
import com.willfp.boosters.boosters.Boosters
|
||||
import com.willfp.boosters.commands.CommandBoosters
|
||||
import com.willfp.boosters.config.DataYml
|
||||
import com.willfp.boosters.data.SaveHandler
|
||||
@@ -10,10 +11,16 @@ import org.bukkit.event.Listener
|
||||
import java.io.IOException
|
||||
|
||||
class BoostersPlugin : EcoPlugin() {
|
||||
val dataYml: DataYml
|
||||
val dataYml: DataYml = DataYml(this)
|
||||
|
||||
override fun handleReload() {
|
||||
save(this)
|
||||
scheduler.runTimer(SaveHandler.Runnable(this), 20000, 20000)
|
||||
scheduler.runTimer(SaveHandler.Runnable(this), 10000, 20000)
|
||||
|
||||
for (booster in Boosters.values()) {
|
||||
this.eventManager.unregisterListener(booster)
|
||||
this.eventManager.registerListener(booster)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleDisable() {
|
||||
@@ -26,6 +33,7 @@ class BoostersPlugin : EcoPlugin() {
|
||||
|
||||
override fun loadListeners(): List<Listener> {
|
||||
return listOf(
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,7 +48,6 @@ class BoostersPlugin : EcoPlugin() {
|
||||
}
|
||||
|
||||
init {
|
||||
dataYml = DataYml(this)
|
||||
instance = this
|
||||
}
|
||||
|
||||
|
||||
@@ -18,4 +18,12 @@ object Boosters {
|
||||
fun registerNewBooster(booster: Booster) {
|
||||
byId[booster.id] = booster
|
||||
}
|
||||
|
||||
fun values(): List<Booster> {
|
||||
return byId.values.toList()
|
||||
}
|
||||
|
||||
fun names(): List<String> {
|
||||
return byId.keys.toList()
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.willfp.boosters.commands
|
||||
|
||||
import com.willfp.boosters.gui.BoosterGUI
|
||||
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
|
||||
|
||||
@@ -27,7 +27,7 @@ class CommandBoosters(plugin: EcoPlugin) :
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
SkillGUI.getHomeMenu().open(sender)
|
||||
BoosterGUI.open(sender)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.willfp.boosters.commands
|
||||
|
||||
import com.google.common.math.Stats
|
||||
import com.willfp.boosters.boosters.Boosters
|
||||
import com.willfp.boosters.getAmountOfBooster
|
||||
import com.willfp.boosters.setAmountOfBooster
|
||||
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 com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.util.StringUtil
|
||||
|
||||
|
||||
class CommandGive(plugin: EcoPlugin) :
|
||||
Subcommand(
|
||||
plugin,
|
||||
@@ -37,46 +31,30 @@ class CommandGive(plugin: EcoPlugin) :
|
||||
return@CommandHandler
|
||||
}
|
||||
|
||||
val player = Bukkit.getPlayer(args[0])
|
||||
if (player == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return@CommandHandler
|
||||
}
|
||||
val booster = Boosters.getById(args[1].lowercase())
|
||||
|
||||
val obj = Skills.getByID(args[1].lowercase()) ?: Stats.getByID(args[1].lowercase())
|
||||
|
||||
if (obj == null) {
|
||||
if (booster == 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
|
||||
this.plugin.scheduler.runAsync {
|
||||
@Suppress("DEPRECATION")
|
||||
val player = Bukkit.getOfflinePlayer(args[0])
|
||||
if (!player.hasPlayedBefore()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return@runAsync
|
||||
}
|
||||
|
||||
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
|
||||
this.plugin.scheduler.run {
|
||||
player.setAmountOfBooster(booster, player.getAmountOfBooster(booster) + 1)
|
||||
}
|
||||
|
||||
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)
|
||||
plugin.langYml.getMessage("gave-booster", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
|
||||
.replace("%player%", player.name?: return@runAsync)
|
||||
.replace("%booster%", booster.id)
|
||||
)
|
||||
return@CommandHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,16 +75,7 @@ class CommandGive(plugin: EcoPlugin) :
|
||||
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,
|
||||
Boosters.names(),
|
||||
completions
|
||||
)
|
||||
return@TabCompleteHandler completions
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.willfp.boosters.gui
|
||||
|
||||
import com.willfp.boosters.BoostersPlugin
|
||||
import com.willfp.boosters.activateBooster
|
||||
import com.willfp.boosters.activeBooster
|
||||
import com.willfp.boosters.boosters.Booster
|
||||
import com.willfp.boosters.boosters.Boosters
|
||||
import com.willfp.boosters.getAmountOfBooster
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.slot.FillerMask
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.items.builder.SkullBuilder
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import com.willfp.ecoskills.tryAsPlayer
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
object BoosterGUI {
|
||||
private val plugin = BoostersPlugin.instance
|
||||
|
||||
private fun makeHandler(booster: Booster): SlotHandler {
|
||||
return SlotHandler { event, _, _ ->
|
||||
val player = event.whoClicked.tryAsPlayer() ?: return@SlotHandler
|
||||
|
||||
if (Bukkit.getServer().activeBooster != null) {
|
||||
player.sendMessage(plugin.langYml.getMessage("already-active"))
|
||||
player.playSound(
|
||||
player.location,
|
||||
Sound.BLOCK_NOTE_BLOCK_PLING,
|
||||
1f,
|
||||
0.5f
|
||||
)
|
||||
return@SlotHandler
|
||||
}
|
||||
|
||||
if (!player.activateBooster(booster)) {
|
||||
player.sendMessage(plugin.langYml.getMessage("dont-have"))
|
||||
player.playSound(
|
||||
player.location,
|
||||
Sound.BLOCK_NOTE_BLOCK_PLING,
|
||||
1f,
|
||||
0.5f
|
||||
)
|
||||
return@SlotHandler
|
||||
}
|
||||
|
||||
player.closeInventory()
|
||||
}
|
||||
}
|
||||
|
||||
private val gui = Menu.builder(3)
|
||||
.setMask(
|
||||
FillerMask(
|
||||
Material.BLACK_STAINED_GLASS_PANE,
|
||||
"111111111",
|
||||
"101101101",
|
||||
"111111111"
|
||||
)
|
||||
)
|
||||
.setSlot(
|
||||
2,
|
||||
2,
|
||||
Slot.builder(
|
||||
SkullBuilder()
|
||||
.setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM0YjI3YmZjYzhmOWI5NjQ1OTRiNjE4YjExNDZhZjY5ZGUyNzhjZTVlMmUzMDEyY2I0NzFhOWEzY2YzODcxIn19fQ==")
|
||||
.build()
|
||||
)
|
||||
.setModifier { player, _, previous ->
|
||||
val meta = previous.itemMeta ?: return@setModifier
|
||||
val lore = mutableListOf<String>()
|
||||
|
||||
lore.add("")
|
||||
lore.add("&fGives everyone online a")
|
||||
lore.add("&a1.5x Sell Multiplier")
|
||||
lore.add("&fto make money faster!")
|
||||
lore.add("")
|
||||
lore.add("&fDuration: &a1 Hour")
|
||||
lore.add("")
|
||||
lore.add("&fYou have: &a${player.getAmountOfBooster(Boosters.SELL_MULTIPLIER_LOW)}")
|
||||
lore.add("Get more at &astore.ecomc.net")
|
||||
lore.add("")
|
||||
lore.add("&e&oClick to activate!")
|
||||
lore.add("")
|
||||
|
||||
meta.setDisplayName("&a1.5x Sell Multiplier")
|
||||
|
||||
meta.lore = lore.apply {
|
||||
replaceAll { StringUtils.format(it) }
|
||||
}
|
||||
previous.itemMeta = meta
|
||||
|
||||
}
|
||||
.onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_LOW))
|
||||
.build()
|
||||
)
|
||||
.setSlot(
|
||||
2,
|
||||
5,
|
||||
Slot.builder(
|
||||
SkullBuilder()
|
||||
.setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjBhN2I5NGM0ZTU4MWI2OTkxNTlkNDg4NDZlYzA5MTM5MjUwNjIzN2M4OWE5N2M5MzI0OGEwZDhhYmM5MTZkNSJ9fX0=")
|
||||
.build()
|
||||
)
|
||||
.setModifier { player, _, previous ->
|
||||
val meta = previous.itemMeta ?: return@setModifier
|
||||
val lore = mutableListOf<String>()
|
||||
|
||||
lore.add("")
|
||||
lore.add("&fGives everyone online a")
|
||||
lore.add("&a2x Sell Multiplier")
|
||||
lore.add("&fto make money faster!")
|
||||
lore.add("")
|
||||
lore.add("&fDuration: &a1 Hour")
|
||||
lore.add("")
|
||||
lore.add("&fYou have: &a${player.getAmountOfBooster(Boosters.SELL_MULTIPLIER_HIGH)}")
|
||||
lore.add("Get more at &astore.ecomc.net")
|
||||
lore.add("")
|
||||
lore.add("&e&oClick to activate!")
|
||||
lore.add("")
|
||||
|
||||
meta.setDisplayName("&a2x Sell Multiplier")
|
||||
|
||||
meta.lore = lore.apply {
|
||||
replaceAll { StringUtils.format(it) }
|
||||
}
|
||||
previous.itemMeta = meta
|
||||
|
||||
}
|
||||
.onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_HIGH))
|
||||
.build()
|
||||
)
|
||||
.setSlot(
|
||||
2,
|
||||
8,
|
||||
Slot.builder(
|
||||
SkullBuilder()
|
||||
.setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODkyNmMxZjJjM2MxNGQwODZjNDBjZmMyMzVmZTkzODY5NGY0YTUxMDY3YWRhNDcyNmI0ODZlYTFjODdiMDNlMiJ9fX0=")
|
||||
.build()
|
||||
)
|
||||
.setModifier { player, _, previous ->
|
||||
val meta = previous.itemMeta ?: return@setModifier
|
||||
val lore = mutableListOf<String>()
|
||||
|
||||
lore.add("")
|
||||
lore.add("&fGives everyone online a")
|
||||
lore.add("&a2x Skill XP Multiplier")
|
||||
lore.add("&fto level up faster!")
|
||||
lore.add("")
|
||||
lore.add("&fDuration: &a1 Hour")
|
||||
lore.add("")
|
||||
lore.add("&fYou have: &a${player.getAmountOfBooster(Boosters.SKILL_XP)}")
|
||||
lore.add("Get more at &astore.ecomc.net")
|
||||
lore.add("")
|
||||
lore.add("&e&oClick to activate!")
|
||||
lore.add("")
|
||||
|
||||
meta.setDisplayName("&a2x Skill XP Multiplier")
|
||||
|
||||
meta.lore = lore.apply {
|
||||
replaceAll { StringUtils.format(it) }
|
||||
}
|
||||
previous.itemMeta = meta
|
||||
|
||||
}
|
||||
.onLeftClick(makeHandler(Boosters.SKILL_XP))
|
||||
.build()
|
||||
)
|
||||
.setTitle("Boosters")
|
||||
.build()
|
||||
|
||||
fun open(player: Player) {
|
||||
gui.open(player)
|
||||
}
|
||||
}
|
||||
@@ -9,3 +9,5 @@ messages:
|
||||
requires-booster: "&cYou must specify a booster!"
|
||||
invalid-booster: "&cInvalid booster!"
|
||||
gave-booster: "Gave %player% %booster%!"
|
||||
already-active: "&cA booster is already active!"
|
||||
dont-have: "&cYou don't have any of these boosters! Get some at &astore.ecomc.net"
|
||||
|
||||
Reference in New Issue
Block a user