Finished up

This commit is contained in:
Auxilor
2021-09-14 10:53:33 +01:00
parent 11fbb298ca
commit db8381ec48
7 changed files with 229 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ import com.willfp.boosters.boosters.Boosters
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer import org.bukkit.OfflinePlayer
import org.bukkit.Server import org.bukkit.Server
import org.bukkit.Sound
import org.bukkit.entity.Player import org.bukkit.entity.Player
private var active: Booster? = null private var active: Booster? = null
@@ -66,6 +67,15 @@ fun Player.activateBooster(booster: Booster): Boolean {
active = booster active = booster
for (player in Bukkit.getOnlinePlayers()) {
player.playSound(
player.location,
Sound.UI_TOAST_CHALLENGE_COMPLETE,
2f,
0.9f
)
}
return true return true
} }

View File

@@ -1,5 +1,6 @@
package com.willfp.boosters package com.willfp.boosters
import com.willfp.boosters.boosters.Boosters
import com.willfp.boosters.commands.CommandBoosters import com.willfp.boosters.commands.CommandBoosters
import com.willfp.boosters.config.DataYml import com.willfp.boosters.config.DataYml
import com.willfp.boosters.data.SaveHandler import com.willfp.boosters.data.SaveHandler
@@ -10,10 +11,16 @@ import org.bukkit.event.Listener
import java.io.IOException import java.io.IOException
class BoostersPlugin : EcoPlugin() { class BoostersPlugin : EcoPlugin() {
val dataYml: DataYml val dataYml: DataYml = DataYml(this)
override fun handleReload() { override fun handleReload() {
save(this) 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() { override fun handleDisable() {
@@ -26,6 +33,7 @@ class BoostersPlugin : EcoPlugin() {
override fun loadListeners(): List<Listener> { override fun loadListeners(): List<Listener> {
return listOf( return listOf(
) )
} }
@@ -40,7 +48,6 @@ class BoostersPlugin : EcoPlugin() {
} }
init { init {
dataYml = DataYml(this)
instance = this instance = this
} }

View File

@@ -18,4 +18,12 @@ object Boosters {
fun registerNewBooster(booster: Booster) { fun registerNewBooster(booster: Booster) {
byId[booster.id] = booster byId[booster.id] = booster
} }
fun values(): List<Booster> {
return byId.values.toList()
}
fun names(): List<String> {
return byId.keys.toList()
}
} }

View File

@@ -1,9 +1,9 @@
package com.willfp.boosters.commands package com.willfp.boosters.commands
import com.willfp.boosters.gui.BoosterGUI
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.CommandHandler import com.willfp.eco.core.command.CommandHandler
import com.willfp.eco.core.command.impl.PluginCommand import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.boosters.gui.SkillGUI
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.entity.Player import org.bukkit.entity.Player
@@ -27,7 +27,7 @@ class CommandBoosters(plugin: EcoPlugin) :
return@CommandHandler return@CommandHandler
} }
SkillGUI.getHomeMenu().open(sender) BoosterGUI.open(sender)
} }
} }
} }

View File

@@ -1,23 +1,17 @@
package com.willfp.boosters.commands 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.EcoPlugin
import com.willfp.eco.core.command.CommandHandler import com.willfp.eco.core.command.CommandHandler
import com.willfp.eco.core.command.TabCompleteHandler import com.willfp.eco.core.command.TabCompleteHandler
import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.core.command.impl.Subcommand
import com.willfp.boosters.getStatLevel import com.willfp.eco.util.StringUtils
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.Bukkit
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.util.StringUtil import org.bukkit.util.StringUtil
class CommandGive(plugin: EcoPlugin) : class CommandGive(plugin: EcoPlugin) :
Subcommand( Subcommand(
plugin, plugin,
@@ -37,46 +31,30 @@ class CommandGive(plugin: EcoPlugin) :
return@CommandHandler return@CommandHandler
} }
val player = Bukkit.getPlayer(args[0]) val booster = Boosters.getById(args[1].lowercase())
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 (booster == null) {
if (obj == null) {
sender.sendMessage(plugin.langYml.getMessage("invalid-booster")) sender.sendMessage(plugin.langYml.getMessage("invalid-booster"))
return@CommandHandler return@CommandHandler
} }
val amount = args[2].toIntOrNull() 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 (amount == null) { this.plugin.scheduler.run {
sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) player.setAmountOfBooster(booster, player.getAmountOfBooster(booster) + 1)
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( sender.sendMessage(
this.plugin.langYml.getMessage("gave-stat") plugin.langYml.getMessage("gave-booster", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%player%", player.name) .replace("%player%", player.name?: return@runAsync)
.replace("%amount%", amount.toString()) .replace("%booster%", booster.id)
.replace("%stat%", obj.name)
) )
return@CommandHandler
} }
} }
} }
@@ -97,16 +75,7 @@ class CommandGive(plugin: EcoPlugin) :
if (args.size == 2) { if (args.size == 2) {
StringUtil.copyPartialMatches( StringUtil.copyPartialMatches(
args[1], args[1],
TabCompleteHelper.SKILL_NAMES union TabCompleteHelper.STAT_NAMES, Boosters.names(),
completions
)
return@TabCompleteHandler completions
}
if (args.size == 3) {
StringUtil.copyPartialMatches(
args[2],
TabCompleteHelper.AMOUNTS,
completions completions
) )
return@TabCompleteHandler completions return@TabCompleteHandler completions

View File

@@ -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)
}
}

View File

@@ -9,3 +9,5 @@ messages:
requires-booster: "&cYou must specify a booster!" requires-booster: "&cYou must specify a booster!"
invalid-booster: "&cInvalid booster!" invalid-booster: "&cInvalid booster!"
gave-booster: "Gave %player% %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"