Rebranded as EcoItems
This commit is contained in:
25
README.md
25
README.md
@@ -1,22 +1,22 @@
|
|||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<br>
|
<br>
|
||||||
<img src="https://i.imgur.com/Zy0MpbE.png" alt="EcoWeapons logo" width="256">
|
<img src="https://i.imgur.com/Zy0MpbE.png" alt="EcoItems logo" width="256">
|
||||||
<br>
|
<br>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h4 align="center">Source code for EcoWeapons, a premium spigot plugin.</h4>
|
<h4 align="center">Source code for EcoItems, a premium spigot plugin.</h4>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://polymart.org/resource/1-16-1-17-ecoweapons.1241">
|
<a href="https://polymart.org/resource/ecoitems.1241">
|
||||||
<img alt="spigot" src="https://img.shields.io/badge/polymart-ecoweapons-ff0000?style=for-the-badge"/>
|
<img alt="spigot" src="https://img.shields.io/badge/polymart-ecoitems-ff0000?style=for-the-badge"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://bstats.org/plugin/bukkit/EcoWeapons" alt="bstats servers">
|
<a href="https://bstats.org/plugin/bukkit/EcoItems" alt="bstats servers">
|
||||||
<img src="https://img.shields.io/bstats/servers/12134?color=ff0000&style=for-the-badge"/>
|
<img src="https://img.shields.io/bstats/servers/12205?color=ff0000&style=for-the-badge"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://bstats.org/plugin/bukkit/EcoWeapons" alt="bstats players">
|
<a href="https://bstats.org/plugin/bukkit/EcoItems" alt="bstats players">
|
||||||
<img src="https://img.shields.io/bstats/players/12134?color=ff0000&style=for-the-badge"/>
|
<img src="https://img.shields.io/bstats/players/12205?color=ff0000&style=for-the-badge"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://ecoweapons.willfp.com/" alt="Docs (gitbook)">
|
<a href="https://plugins.auxilor.io/ecoitems/" alt="Docs (gitbook)">
|
||||||
<img src="https://img.shields.io/badge/docs-gitbook-ff0000?style=for-the-badge&logo=appveyor"/>
|
<img src="https://img.shields.io/badge/docs-gitbook-ff0000?style=for-the-badge&logo=appveyor"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://discord.gg/ZcwpSsE/" alt="Discord">
|
<a href="https://discord.gg/ZcwpSsE/" alt="Discord">
|
||||||
@@ -25,13 +25,10 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
[]()
|
[]()
|
||||||
[]()
|
|
||||||
[](https://ecoweapons.willfp.com/)
|
|
||||||
[]()
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
*Click here to read [the entire license](https://github.com/Auxilor/EcoWeapons/blob/master/LICENSE.md).*
|
*Click here to read [the entire license](https://github.com/Auxilor/EcoItems/blob/master/LICENSE.md).*
|
||||||
|
|
||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -57,12 +57,12 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate('com.willfp.libreforge', 'com.willfp.ecoweapons.libreforge')
|
relocate('com.willfp.libreforge', 'com.willfp.ecoitems.libreforge')
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'com.willfp:eco:6.15.0'
|
compileOnly 'com.willfp:eco:6.17.1'
|
||||||
implementation 'com.willfp:libreforge:2.6.2'
|
implementation 'com.willfp:libreforge:2.7.0'
|
||||||
|
|
||||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
package com.willfp.ecoweapons
|
package com.willfp.ecoitems
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.impl.PluginCommand
|
||||||
import com.willfp.eco.core.display.DisplayModule
|
import com.willfp.eco.core.display.DisplayModule
|
||||||
import com.willfp.eco.core.integrations.IntegrationLoader
|
import com.willfp.eco.core.integrations.IntegrationLoader
|
||||||
import com.willfp.ecoweapons.commands.CommandEcoweapons
|
import com.willfp.ecoitems.commands.CommandEcoItems
|
||||||
import com.willfp.ecoweapons.config.EcoWeaponsYml
|
import com.willfp.ecoitems.config.ItemsYml
|
||||||
import com.willfp.ecoweapons.display.WeaponsDisplay
|
import com.willfp.ecoitems.display.ItemsDisplay
|
||||||
import com.willfp.ecoweapons.fuels.FuelHandler
|
import com.willfp.ecoitems.fuels.FuelHandler
|
||||||
import com.willfp.ecoweapons.util.DiscoverRecipeListener
|
import com.willfp.ecoitems.util.DiscoverRecipeListener
|
||||||
import com.willfp.ecoweapons.weapons.WeaponListener
|
import com.willfp.ecoitems.items.ItemListener
|
||||||
import com.willfp.ecoweapons.weapons.WeaponModifierListener
|
import com.willfp.ecoitems.items.ItemAttributeListener
|
||||||
import com.willfp.ecoweapons.weapons.WeaponUtils
|
import com.willfp.ecoitems.items.ItemUtils
|
||||||
import com.willfp.ecoweapons.weapons.toSingletonList
|
import com.willfp.ecoitems.items.toSingletonList
|
||||||
import com.willfp.libreforge.LibReforge
|
import com.willfp.libreforge.LibReforge
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
|
||||||
class EcoWeaponsPlugin : EcoPlugin(1241, 12134, "&#ff0000", true) {
|
class EcoItemsPlugin : EcoPlugin(1241, 12205, "&#ff0000", true) {
|
||||||
/**
|
/**
|
||||||
* ecoweapons.yml.
|
* items.yml.
|
||||||
*/
|
*/
|
||||||
val ecoWeaponsYml: EcoWeaponsYml
|
val itemsYml: ItemsYml
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal constructor called by bukkit on plugin load.
|
* Internal constructor called by bukkit on plugin load.
|
||||||
*/
|
*/
|
||||||
init {
|
init {
|
||||||
instance = this
|
instance = this
|
||||||
ecoWeaponsYml = EcoWeaponsYml(this)
|
itemsYml = ItemsYml(this)
|
||||||
LibReforge.init(this)
|
LibReforge.init(this)
|
||||||
LibReforge.registerHolderProvider { WeaponUtils.getWeaponOnPlayer(it).toSingletonList() }
|
LibReforge.registerHolderProvider { ItemUtils.getEcoItemOnPlayer(it).toSingletonList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleEnable() {
|
override fun handleEnable() {
|
||||||
@@ -48,9 +48,9 @@ class EcoWeaponsPlugin : EcoPlugin(1241, 12134, "&#ff0000", true) {
|
|||||||
override fun loadListeners(): List<Listener> {
|
override fun loadListeners(): List<Listener> {
|
||||||
return listOf(
|
return listOf(
|
||||||
DiscoverRecipeListener(this),
|
DiscoverRecipeListener(this),
|
||||||
WeaponListener(this),
|
ItemListener(this),
|
||||||
FuelHandler(),
|
FuelHandler(),
|
||||||
WeaponModifierListener(this)
|
ItemAttributeListener(this)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,12 +60,12 @@ class EcoWeaponsPlugin : EcoPlugin(1241, 12134, "&#ff0000", true) {
|
|||||||
|
|
||||||
override fun loadPluginCommands(): List<PluginCommand> {
|
override fun loadPluginCommands(): List<PluginCommand> {
|
||||||
return listOf(
|
return listOf(
|
||||||
CommandEcoweapons(this)
|
CommandEcoItems(this)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createDisplayModule(): DisplayModule {
|
override fun createDisplayModule(): DisplayModule {
|
||||||
return WeaponsDisplay(this)
|
return ItemsDisplay(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMinimumEcoVersion(): String {
|
override fun getMinimumEcoVersion(): String {
|
||||||
@@ -74,9 +74,9 @@ class EcoWeaponsPlugin : EcoPlugin(1241, 12134, "&#ff0000", true) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Instance of EcoWeapons.
|
* Instance of EcoItems.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var instance: EcoWeaponsPlugin
|
lateinit var instance: EcoItemsPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.willfp.ecoitems.commands
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
|
import com.willfp.eco.core.command.CommandHandler
|
||||||
|
import com.willfp.eco.core.command.impl.PluginCommand
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
|
class CommandEcoItems(
|
||||||
|
plugin: EcoPlugin
|
||||||
|
) : PluginCommand(
|
||||||
|
plugin,
|
||||||
|
"ecoitems",
|
||||||
|
"ecoitems.command.ecoitems",
|
||||||
|
false) {
|
||||||
|
init {
|
||||||
|
addSubcommand(CommandReload(plugin))
|
||||||
|
.addSubcommand(CommandGive(plugin))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
|
sender.sendMessage(
|
||||||
|
plugin.langYml.getMessage("invalid-command")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.willfp.ecoitems.commands
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
|
import com.willfp.eco.core.command.impl.Subcommand
|
||||||
|
import com.willfp.ecoitems.fuels.Fuels
|
||||||
|
import com.willfp.ecoitems.items.EcoItems
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import org.bukkit.util.StringUtil
|
||||||
|
|
||||||
|
class CommandGive(plugin: EcoPlugin) : Subcommand(plugin, "give", "ecoitems.command.give", false) {
|
||||||
|
private val numbers = listOf(
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"10",
|
||||||
|
"32",
|
||||||
|
"64"
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("needs-player"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (args.size == 1) {
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("needs-item"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val receiverName = args[0]
|
||||||
|
val receiver = Bukkit.getPlayer(receiverName)
|
||||||
|
if (receiver == null) {
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val itemID = args[1]
|
||||||
|
var amount = 1
|
||||||
|
val ecoItem = EcoItems.getByID(itemID.lowercase())
|
||||||
|
val fuel = Fuels.getByID(itemID.lowercase())
|
||||||
|
if (ecoItem == null && fuel == null) {
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("invalid-item"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var message = plugin.langYml.getMessage("give-success")
|
||||||
|
message = message.replace("%item%", itemID).replace("%recipient%", receiver.name)
|
||||||
|
sender.sendMessage(message)
|
||||||
|
if (args.size == 3) {
|
||||||
|
amount = args[2].toIntOrNull() ?: 1
|
||||||
|
}
|
||||||
|
val item: ItemStack = ecoItem?.itemStack ?: fuel?.itemStack!!
|
||||||
|
item.amount = amount
|
||||||
|
receiver.inventory.addItem(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||||
|
val completions = mutableListOf<String>()
|
||||||
|
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
return EcoItems.values().map { it.id }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size == 1) {
|
||||||
|
StringUtil.copyPartialMatches(
|
||||||
|
args[0],
|
||||||
|
Bukkit.getOnlinePlayers().map { it.name },
|
||||||
|
completions
|
||||||
|
)
|
||||||
|
return completions
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size == 2) {
|
||||||
|
val itemNames = EcoItems.values().map { it.id } union Fuels.values().map { it.id }
|
||||||
|
|
||||||
|
StringUtil.copyPartialMatches(args[1], itemNames, completions)
|
||||||
|
completions.sort()
|
||||||
|
return completions
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size == 3) {
|
||||||
|
StringUtil.copyPartialMatches(args[2], numbers, completions)
|
||||||
|
return completions
|
||||||
|
}
|
||||||
|
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.willfp.ecoitems.commands
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
|
import com.willfp.eco.core.command.impl.Subcommand
|
||||||
|
import com.willfp.eco.core.command.CommandHandler
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
|
class CommandReload(plugin: EcoPlugin) : Subcommand(plugin, "reload", "ecoitems.command.reload", false) {
|
||||||
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
|
plugin.reload()
|
||||||
|
sender.sendMessage(plugin.langYml.getMessage("reloaded"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.willfp.ecoitems.config
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin
|
||||||
|
import com.willfp.eco.core.config.BaseConfig
|
||||||
|
import com.willfp.eco.core.config.ConfigType
|
||||||
|
|
||||||
|
class ItemsYml(plugin: EcoPlugin) : BaseConfig("items", plugin, false, ConfigType.YAML)
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
package com.willfp.ecoweapons.display
|
package com.willfp.ecoitems.display
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.display.DisplayModule
|
import com.willfp.eco.core.display.DisplayModule
|
||||||
import com.willfp.eco.core.display.DisplayPriority
|
import com.willfp.eco.core.display.DisplayPriority
|
||||||
import com.willfp.ecoweapons.fuels.FuelUtils
|
import com.willfp.ecoitems.fuels.FuelUtils
|
||||||
import com.willfp.ecoweapons.weapons.WeaponUtils
|
import com.willfp.ecoitems.items.ItemUtils
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
class WeaponsDisplay(plugin: EcoPlugin) : DisplayModule(plugin, DisplayPriority.LOWEST) {
|
class ItemsDisplay(plugin: EcoPlugin) : DisplayModule(plugin, DisplayPriority.LOWEST) {
|
||||||
override fun display(
|
override fun display(
|
||||||
itemStack: ItemStack,
|
itemStack: ItemStack,
|
||||||
vararg args: Any
|
vararg args: Any
|
||||||
) {
|
) {
|
||||||
val meta = itemStack.itemMeta ?: return
|
val meta = itemStack.itemMeta ?: return
|
||||||
val weapon = WeaponUtils.getWeaponFromItem(meta)
|
val ecoItem = ItemUtils.getEcoItem(meta)
|
||||||
val fuel = FuelUtils.getFuelFromItem(meta)
|
val fuel = FuelUtils.getFuelFromItem(meta)
|
||||||
|
|
||||||
if (fuel != null) {
|
if (fuel != null) {
|
||||||
@@ -29,17 +29,17 @@ class WeaponsDisplay(plugin: EcoPlugin) : DisplayModule(plugin, DisplayPriority.
|
|||||||
itemStack.itemMeta = meta
|
itemStack.itemMeta = meta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weapon != null) {
|
if (ecoItem != null) {
|
||||||
val weaponMeta = weapon.itemStack.itemMeta ?: return
|
val ecoItemMeta = ecoItem.itemStack.itemMeta ?: return
|
||||||
val lore: MutableList<String> = weaponMeta.lore?.toMutableList() ?: return
|
val lore: MutableList<String> = ecoItemMeta.lore?.toMutableList() ?: return
|
||||||
|
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore.addAll(meta.lore ?: return)
|
lore.addAll(meta.lore ?: return)
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.lore = lore
|
meta.lore = lore
|
||||||
meta.setDisplayName(weaponMeta.displayName)
|
meta.setDisplayName(ecoItemMeta.displayName)
|
||||||
meta.addItemFlags(*weaponMeta.itemFlags.toTypedArray())
|
meta.addItemFlags(*ecoItemMeta.itemFlags.toTypedArray())
|
||||||
itemStack.itemMeta = meta
|
itemStack.itemMeta = meta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.fuels
|
package com.willfp.ecoitems.fuels
|
||||||
|
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
import com.willfp.libreforge.ConfigViolation
|
import com.willfp.libreforge.ConfigViolation
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.fuels
|
package com.willfp.ecoitems.fuels
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
@@ -59,6 +59,6 @@ class Fuel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Weapon{$id}"
|
return "Fuel{$id}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.willfp.ecoweapons.fuels
|
package com.willfp.ecoitems.fuels
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.ecoweapons.weapons.Weapon
|
import com.willfp.ecoitems.items.EcoItem
|
||||||
import com.willfp.libreforge.events.EffectActivateEvent
|
import com.willfp.libreforge.events.EffectActivateEvent
|
||||||
import com.willfp.libreforge.updateEffects
|
import com.willfp.libreforge.updateEffects
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
@@ -11,25 +11,25 @@ import org.bukkit.event.Listener
|
|||||||
|
|
||||||
class FuelHandler : Listener {
|
class FuelHandler : Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onUseWeapon(event: EffectActivateEvent) {
|
fun onUseItem(event: EffectActivateEvent) {
|
||||||
val weapon = event.holder as? Weapon ?: return
|
val item = event.holder as? EcoItem ?: return
|
||||||
if (weapon.fuels.isEmpty()) {
|
if (item.fuels.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
queue[event.player] = weapon
|
queue[event.player] = item
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val queue = mutableMapOf<Player, Weapon>()
|
private val queue = mutableMapOf<Player, EcoItem>()
|
||||||
|
|
||||||
private fun consumeFuel() {
|
private fun consumeFuel() {
|
||||||
for ((player, weapon) in queue.toMap()) {
|
for ((player, item) in queue.toMap()) {
|
||||||
fuelIter@ for (fuel in weapon.fuels) {
|
fuelIter@ for (fuel in item.fuels) {
|
||||||
for (i in player.inventory.contents.indices) {
|
for (i in player.inventory.contents.indices) {
|
||||||
val itemStack = player.inventory.getItem(i) ?: continue
|
val itemStack = player.inventory.getItem(i) ?: continue
|
||||||
|
|
||||||
if (weapon.fuels.contains(FuelUtils.getFuelFromItem(itemStack))) {
|
if (item.fuels.contains(FuelUtils.getFuelFromItem(itemStack))) {
|
||||||
if (itemStack.amount == 1) {
|
if (itemStack.amount == 1) {
|
||||||
itemStack.type = Material.AIR
|
itemStack.type = Material.AIR
|
||||||
} else {
|
} else {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.willfp.ecoweapons.fuels
|
package com.willfp.ecoitems.fuels
|
||||||
|
|
||||||
import com.willfp.ecoweapons.EcoWeaponsPlugin.Companion.instance
|
import com.willfp.ecoitems.EcoItemsPlugin.Companion.instance
|
||||||
import com.willfp.ecoweapons.weapons.Weapon
|
import com.willfp.ecoitems.items.EcoItem
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.ItemMeta
|
import org.bukkit.inventory.meta.ItemMeta
|
||||||
@@ -9,15 +9,15 @@ import org.bukkit.persistence.PersistentDataType
|
|||||||
|
|
||||||
object FuelUtils {
|
object FuelUtils {
|
||||||
/**
|
/**
|
||||||
* Instance of EcoWeapons.
|
* Instance of EcoItems.
|
||||||
*/
|
*/
|
||||||
private val PLUGIN = instance
|
private val PLUGIN = instance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fuel weapon from an item.
|
* Get fuel from an item.
|
||||||
*
|
*
|
||||||
* @param itemStack The itemStack to check.
|
* @param itemStack The itemStack to check.
|
||||||
* @return The weapon, or null if no weapon is found.
|
* @return The fuel, or null if no fuel is found.
|
||||||
*/
|
*/
|
||||||
fun getFuelFromItem(itemStack: ItemStack?): Fuel? {
|
fun getFuelFromItem(itemStack: ItemStack?): Fuel? {
|
||||||
itemStack ?: return null
|
itemStack ?: return null
|
||||||
@@ -26,10 +26,10 @@ object FuelUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fuel weapon on an item.
|
* Get fuel on an item.
|
||||||
*
|
*
|
||||||
* @param meta The itemStack to check.
|
* @param meta The itemStack to check.
|
||||||
* @return The weapon, or null if no weapon is found.
|
* @return The fuel, or null if no fuel is found.
|
||||||
*/
|
*/
|
||||||
fun getFuelFromItem(meta: ItemMeta): Fuel? {
|
fun getFuelFromItem(meta: ItemMeta): Fuel? {
|
||||||
val container = meta.persistentDataContainer
|
val container = meta.persistentDataContainer
|
||||||
@@ -41,17 +41,17 @@ object FuelUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If player has fuel for a weapon.
|
* If player has fuel for an item.
|
||||||
*
|
*
|
||||||
* @param player The player to check.
|
* @param player The player to check.
|
||||||
* @param weapon The weapon.
|
* @param item The item.
|
||||||
* @return If the player has fuel for it.
|
* @return If the player has fuel for it.
|
||||||
*/
|
*/
|
||||||
fun hasFuelFor(player: Player, weapon: Weapon): Boolean {
|
fun hasFuelFor(player: Player, item: EcoItem): Boolean {
|
||||||
if (weapon.fuels.isEmpty()) {
|
if (item.fuels.isEmpty()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for (fuel in weapon.fuels) {
|
for (fuel in item.fuels) {
|
||||||
if (hasFuel(player, fuel)) {
|
if (hasFuel(player, fuel)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.willfp.ecoweapons.fuels
|
package com.willfp.ecoitems.fuels
|
||||||
|
|
||||||
import com.google.common.collect.BiMap
|
import com.google.common.collect.BiMap
|
||||||
import com.google.common.collect.HashBiMap
|
import com.google.common.collect.HashBiMap
|
||||||
import com.google.common.collect.ImmutableList
|
import com.google.common.collect.ImmutableList
|
||||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||||
import com.willfp.ecoweapons.EcoWeaponsPlugin
|
import com.willfp.ecoitems.EcoItemsPlugin
|
||||||
|
|
||||||
object Fuels {
|
object Fuels {
|
||||||
/**
|
/**
|
||||||
@@ -38,21 +38,21 @@ object Fuels {
|
|||||||
/**
|
/**
|
||||||
* Update all [Fuel]s.
|
* Update all [Fuel]s.
|
||||||
*
|
*
|
||||||
* @param plugin Instance of EcoWeapons.
|
* @param plugin Instance of EcoItems.
|
||||||
*/
|
*/
|
||||||
@ConfigUpdater
|
@ConfigUpdater
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun update(plugin: EcoWeaponsPlugin) {
|
fun update(plugin: EcoItemsPlugin) {
|
||||||
for (fuel in values()) {
|
for (fuel in values()) {
|
||||||
removeFuel(fuel)
|
removeFuel(fuel)
|
||||||
}
|
}
|
||||||
for (setConfig in plugin.ecoWeaponsYml.getSubsections("fuels")) {
|
for (setConfig in plugin.itemsYml.getSubsections("fuels")) {
|
||||||
addNewFuel(Fuel(setConfig, plugin))
|
addNewFuel(Fuel(setConfig, plugin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new [Fuel] to EcoWeapons.
|
* Add new [Fuel] to EcoItems.
|
||||||
*
|
*
|
||||||
* @param fuel The [Fuel] to add.
|
* @param fuel The [Fuel] to add.
|
||||||
*/
|
*/
|
||||||
@@ -63,9 +63,9 @@ object Fuels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove [Fuel] from EcoWeapons.
|
* Remove [Fuel] from EcoItems.
|
||||||
*
|
*
|
||||||
* @param weapon The [Fuel] to remove.
|
* @param fuel The [Fuel] to remove.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun removeFuel(fuel: Fuel) {
|
fun removeFuel(fuel: Fuel) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.weapons
|
package com.willfp.ecoitems.items
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
@@ -7,7 +7,7 @@ import com.willfp.eco.core.items.CustomItem
|
|||||||
import com.willfp.eco.core.items.Items
|
import com.willfp.eco.core.items.Items
|
||||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||||
import com.willfp.eco.core.recipe.Recipes
|
import com.willfp.eco.core.recipe.Recipes
|
||||||
import com.willfp.ecoweapons.fuels.Fuels
|
import com.willfp.ecoitems.fuels.Fuels
|
||||||
import com.willfp.libreforge.Holder
|
import com.willfp.libreforge.Holder
|
||||||
import com.willfp.libreforge.conditions.Conditions
|
import com.willfp.libreforge.conditions.Conditions
|
||||||
import com.willfp.libreforge.effects.Effects
|
import com.willfp.libreforge.effects.Effects
|
||||||
@@ -15,18 +15,18 @@ import org.bukkit.inventory.ItemStack
|
|||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
|
|
||||||
class Weapon(
|
class EcoItem(
|
||||||
private val config: Config,
|
private val config: Config,
|
||||||
private val plugin: EcoPlugin
|
private val plugin: EcoPlugin
|
||||||
) : Holder {
|
) : Holder {
|
||||||
val id = config.getString("id")
|
val id = config.getString("id")
|
||||||
|
|
||||||
override val effects = config.getSubsections("effects").mapNotNull {
|
override val effects = config.getSubsections("effects").mapNotNull {
|
||||||
Effects.compile(it, "Weapon ID $id")
|
Effects.compile(it, "Item ID $id")
|
||||||
}.toSet()
|
}.toSet()
|
||||||
|
|
||||||
override val conditions = config.getSubsections("conditions").mapNotNull {
|
override val conditions = config.getSubsections("conditions").mapNotNull {
|
||||||
Conditions.compile(it, "Weapon ID $id")
|
Conditions.compile(it, "Item ID $id")
|
||||||
}.toSet()
|
}.toSet()
|
||||||
|
|
||||||
val itemStack: ItemStack = run {
|
val itemStack: ItemStack = run {
|
||||||
@@ -36,16 +36,16 @@ class Weapon(
|
|||||||
addLoreLines(
|
addLoreLines(
|
||||||
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" })
|
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" })
|
||||||
writeMetaKey(
|
writeMetaKey(
|
||||||
this@Weapon.plugin.namespacedKeyFactory.create("weapon"),
|
this@EcoItem.plugin.namespacedKeyFactory.create("item"),
|
||||||
PersistentDataType.STRING,
|
PersistentDataType.STRING,
|
||||||
this@Weapon.id
|
this@EcoItem.id
|
||||||
)
|
)
|
||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
val customItem = CustomItem(
|
val customItem = CustomItem(
|
||||||
plugin.namespacedKeyFactory.create(id),
|
plugin.namespacedKeyFactory.create(id),
|
||||||
{ test -> WeaponUtils.getWeaponFromItem(test) == this },
|
{ test -> ItemUtils.getEcoItem(test) == this },
|
||||||
itemStack
|
itemStack
|
||||||
).apply { register() }
|
).apply { register() }
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class Weapon(
|
|||||||
val baseAttackSpeed = config.getDouble("baseAttackSpeed")
|
val baseAttackSpeed = config.getDouble("baseAttackSpeed")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other !is Weapon) {
|
if (other !is EcoItem) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +77,6 @@ class Weapon(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Weapon{$id}"
|
return "EcoItem{$id}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.willfp.ecoitems.items
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap
|
||||||
|
import com.google.common.collect.HashBiMap
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
|
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||||
|
import com.willfp.ecoitems.EcoItemsPlugin
|
||||||
|
import com.willfp.ecoitems.fuels.ConditionHasFuel
|
||||||
|
|
||||||
|
object EcoItems {
|
||||||
|
/**
|
||||||
|
* Registered items.
|
||||||
|
*/
|
||||||
|
private val BY_ID: BiMap<String, EcoItem> = HashBiMap.create()
|
||||||
|
|
||||||
|
val CONDITION_HAS_FUEL = ConditionHasFuel()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all registered [EcoItem]s.
|
||||||
|
*
|
||||||
|
* @return A list of all [EcoItem]s.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun values(): List<EcoItem> {
|
||||||
|
return ImmutableList.copyOf(BY_ID.values)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get [EcoItem] matching id.
|
||||||
|
*
|
||||||
|
* @param name The id to search for.
|
||||||
|
* @return The matching [EcoItem], or null if not found.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun getByID(name: String): EcoItem? {
|
||||||
|
return BY_ID[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update all [EcoItem]s.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoItems.
|
||||||
|
*/
|
||||||
|
@ConfigUpdater
|
||||||
|
@JvmStatic
|
||||||
|
fun update(plugin: EcoItemsPlugin) {
|
||||||
|
for (item in values()) {
|
||||||
|
removeItem(item)
|
||||||
|
}
|
||||||
|
for (setConfig in plugin.itemsYml.getSubsections("items")) {
|
||||||
|
addNewItem(EcoItem(setConfig, plugin))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new [EcoItem] to EcoItems.
|
||||||
|
*
|
||||||
|
* @param item The [EcoItem] to add.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun addNewItem(item: EcoItem) {
|
||||||
|
BY_ID.remove(item.id)
|
||||||
|
BY_ID[item.id] = item
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove [EcoItem] from EcoItems.
|
||||||
|
*
|
||||||
|
* @param item The [EcoItem] to remove.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun removeItem(item: EcoItem) {
|
||||||
|
BY_ID.remove(item.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.weapons
|
package com.willfp.ecoitems.items
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import org.bukkit.attribute.Attribute
|
import org.bukkit.attribute.Attribute
|
||||||
@@ -9,7 +9,7 @@ import org.bukkit.event.Listener
|
|||||||
import org.bukkit.event.player.PlayerItemHeldEvent
|
import org.bukkit.event.player.PlayerItemHeldEvent
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class WeaponModifierListener(private val plugin: EcoPlugin) : Listener {
|
class ItemAttributeListener(private val plugin: EcoPlugin) : Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun handle(event: PlayerItemHeldEvent) {
|
fun handle(event: PlayerItemHeldEvent) {
|
||||||
if (event.isCancelled) {
|
if (event.isCancelled) {
|
||||||
@@ -21,11 +21,29 @@ class WeaponModifierListener(private val plugin: EcoPlugin) : Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun apply(player: Player) {
|
private fun apply(player: Player) {
|
||||||
val weapon = WeaponUtils.getWeaponOnPlayer(player)
|
val item = ItemUtils.getEcoItemOnPlayer(player)
|
||||||
|
|
||||||
val damageInst = player.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE) ?: return
|
val damageInst = player.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE) ?: return
|
||||||
val speedInst = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED) ?: return
|
val speedInst = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED) ?: return
|
||||||
|
|
||||||
|
damageInst.removeModifier(
|
||||||
|
AttributeModifier(
|
||||||
|
UUID.nameUUIDFromBytes("ecoitems_ad".toByteArray()),
|
||||||
|
"EcoItems Damage",
|
||||||
|
1.0, // Irrelevant
|
||||||
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
|
)
|
||||||
|
)
|
||||||
|
speedInst.removeModifier(
|
||||||
|
AttributeModifier(
|
||||||
|
UUID.nameUUIDFromBytes("ecoitems_as".toByteArray()),
|
||||||
|
"EcoItems Speed",
|
||||||
|
1.0, // Irrelevant
|
||||||
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Legacy
|
||||||
damageInst.removeModifier(
|
damageInst.removeModifier(
|
||||||
AttributeModifier(
|
AttributeModifier(
|
||||||
UUID.nameUUIDFromBytes("ecoweapons_ad".toByteArray()),
|
UUID.nameUUIDFromBytes("ecoweapons_ad".toByteArray()),
|
||||||
@@ -43,21 +61,21 @@ class WeaponModifierListener(private val plugin: EcoPlugin) : Listener {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (weapon != null) {
|
if (item != null) {
|
||||||
damageInst.addModifier(
|
damageInst.addModifier(
|
||||||
AttributeModifier(
|
AttributeModifier(
|
||||||
UUID.nameUUIDFromBytes("ecoweapons_ad".toByteArray()),
|
UUID.nameUUIDFromBytes("ecoitems_ad".toByteArray()),
|
||||||
"EcoWeapons Damage",
|
"EcoItems Damage",
|
||||||
weapon.baseDamage - player.inventory.itemInMainHand.type.getBaseDamage(),
|
item.baseDamage - player.inventory.itemInMainHand.type.getBaseDamage(),
|
||||||
AttributeModifier.Operation.ADD_NUMBER
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
speedInst.addModifier(
|
speedInst.addModifier(
|
||||||
AttributeModifier(
|
AttributeModifier(
|
||||||
UUID.nameUUIDFromBytes("ecoweapons_as".toByteArray()),
|
UUID.nameUUIDFromBytes("ecoitems_as".toByteArray()),
|
||||||
"EcoWeapons Speed",
|
"EcoItems Speed",
|
||||||
weapon.baseAttackSpeed - player.inventory.itemInMainHand.type.getBaseAttackSpeed(),
|
item.baseAttackSpeed - player.inventory.itemInMainHand.type.getBaseAttackSpeed(),
|
||||||
AttributeModifier.Operation.ADD_NUMBER
|
AttributeModifier.Operation.ADD_NUMBER
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.weapons
|
package com.willfp.ecoitems.items
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.libreforge.updateEffects
|
import com.willfp.libreforge.updateEffects
|
||||||
@@ -6,7 +6,7 @@ import org.bukkit.event.EventHandler
|
|||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent
|
import org.bukkit.event.player.PlayerItemHeldEvent
|
||||||
|
|
||||||
class WeaponListener(
|
class ItemListener(
|
||||||
private val plugin: EcoPlugin
|
private val plugin: EcoPlugin
|
||||||
): Listener {
|
): Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -1,53 +1,70 @@
|
|||||||
package com.willfp.ecoweapons.weapons
|
package com.willfp.ecoitems.items
|
||||||
|
|
||||||
import com.willfp.ecoweapons.EcoWeaponsPlugin.Companion.instance
|
import com.willfp.ecoitems.EcoItemsPlugin.Companion.instance
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.ItemMeta
|
import org.bukkit.inventory.meta.ItemMeta
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
|
|
||||||
object WeaponUtils {
|
object ItemUtils {
|
||||||
/**
|
/**
|
||||||
* Instance of EcoWeapons.
|
* Instance of EcoItems.
|
||||||
*/
|
*/
|
||||||
private val PLUGIN = instance
|
private val PLUGIN = instance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get weapon from an item.
|
* Get EcoItem from an item.
|
||||||
*
|
*
|
||||||
* @param itemStack The itemStack to check.
|
* @param itemStack The itemStack to check.
|
||||||
* @return The weapon, or null if no weapon is found.
|
* @return The EcoItem, or null if no EcoItem is found.
|
||||||
*/
|
*/
|
||||||
fun getWeaponFromItem(itemStack: ItemStack?): Weapon? {
|
fun getEcoItem(itemStack: ItemStack?): EcoItem? {
|
||||||
itemStack ?: return null
|
itemStack ?: return null
|
||||||
val meta = itemStack.itemMeta ?: return null
|
val meta = itemStack.itemMeta ?: return null
|
||||||
return getWeaponFromItem(meta)
|
val item = getEcoItem(meta)
|
||||||
|
itemStack.itemMeta = meta
|
||||||
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get weapon on an item.
|
* Get EcoItem from an item.
|
||||||
*
|
*
|
||||||
* @param meta The itemStack to check.
|
* @param meta The itemStack to check.
|
||||||
* @return The weapon, or null if no weapon is found.
|
* @return The EcoItem, or null if no EcoItem is found.
|
||||||
*/
|
*/
|
||||||
fun getWeaponFromItem(meta: ItemMeta): Weapon? {
|
fun getEcoItem(meta: ItemMeta): EcoItem? {
|
||||||
val container = meta.persistentDataContainer
|
val container = meta.persistentDataContainer
|
||||||
val weaponName = container.get(
|
val legacy = container.get(
|
||||||
PLUGIN.namespacedKeyFactory.create("weapon"),
|
PLUGIN.namespacedKeyFactory.create("weapon"),
|
||||||
PersistentDataType.STRING
|
PersistentDataType.STRING
|
||||||
|
)
|
||||||
|
|
||||||
|
if (legacy != null) {
|
||||||
|
container.set(
|
||||||
|
PLUGIN.namespacedKeyFactory.create("item"),
|
||||||
|
PersistentDataType.STRING,
|
||||||
|
legacy
|
||||||
|
)
|
||||||
|
container.remove(PLUGIN.namespacedKeyFactory.create("weapon"))
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = container.get(
|
||||||
|
PLUGIN.namespacedKeyFactory.create("item"),
|
||||||
|
PersistentDataType.STRING
|
||||||
) ?: return null
|
) ?: return null
|
||||||
return Weapons.getByID(weaponName)
|
|
||||||
|
return EcoItems.getByID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get weapon on a player.
|
* Get EcoItem on a player.
|
||||||
*
|
*
|
||||||
* @param player The player to check.
|
* @param player The player to check.
|
||||||
* @return The weapon, or null if no weapon is found.
|
* @return The EcoItem, or null if no EcoItem is found.
|
||||||
*/
|
*/
|
||||||
fun getWeaponOnPlayer(player: Player): Weapon? {
|
fun getEcoItemOnPlayer(player: Player): EcoItem? {
|
||||||
return getWeaponFromItem(player.inventory.itemInMainHand)
|
return getEcoItem(player.inventory.itemInMainHand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +73,7 @@ inline fun <reified T> T?.toSingletonList(): List<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Material.getBaseDamage(): Double {
|
fun Material.getBaseDamage(): Double {
|
||||||
return when(this) {
|
return when (this) {
|
||||||
Material.WOODEN_SWORD -> 4.0
|
Material.WOODEN_SWORD -> 4.0
|
||||||
Material.WOODEN_SHOVEL -> 2.5
|
Material.WOODEN_SHOVEL -> 2.5
|
||||||
Material.WOODEN_PICKAXE -> 2.0
|
Material.WOODEN_PICKAXE -> 2.0
|
||||||
@@ -94,7 +111,7 @@ fun Material.getBaseDamage(): Double {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Material.getBaseAttackSpeed(): Double {
|
fun Material.getBaseAttackSpeed(): Double {
|
||||||
return when(this) {
|
return when (this) {
|
||||||
Material.WOODEN_SWORD -> 1.6
|
Material.WOODEN_SWORD -> 1.6
|
||||||
Material.STONE_SWORD -> 1.6
|
Material.STONE_SWORD -> 1.6
|
||||||
Material.IRON_SWORD -> 1.6
|
Material.IRON_SWORD -> 1.6
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoweapons.util
|
package com.willfp.ecoitems.util
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.willfp.ecoweapons.commands
|
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
|
||||||
import com.willfp.eco.core.command.CommandHandler
|
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
|
||||||
|
|
||||||
class CommandEcoweapons(
|
|
||||||
plugin: EcoPlugin
|
|
||||||
) : PluginCommand(
|
|
||||||
plugin,
|
|
||||||
"ecoweapons",
|
|
||||||
"ecoweapons.command.ecoweapons",
|
|
||||||
false) {
|
|
||||||
init {
|
|
||||||
addSubcommand(CommandReload(plugin))
|
|
||||||
.addSubcommand(CommandGive(plugin))
|
|
||||||
}
|
|
||||||
override fun getHandler(): CommandHandler {
|
|
||||||
return CommandHandler { sender, _ ->
|
|
||||||
sender.sendMessage(
|
|
||||||
plugin.langYml.getMessage("invalid-command")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package com.willfp.ecoweapons.commands
|
|
||||||
|
|
||||||
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.ecoweapons.fuels.Fuels
|
|
||||||
import com.willfp.ecoweapons.weapons.Weapons
|
|
||||||
import org.bukkit.Bukkit
|
|
||||||
import org.bukkit.inventory.ItemStack
|
|
||||||
import org.bukkit.util.StringUtil
|
|
||||||
|
|
||||||
class CommandGive(plugin: EcoPlugin) : Subcommand(plugin, "give", "ecoweapons.command.give", false) {
|
|
||||||
private val numbers = listOf(
|
|
||||||
"1",
|
|
||||||
"2",
|
|
||||||
"3",
|
|
||||||
"4",
|
|
||||||
"5",
|
|
||||||
"10",
|
|
||||||
"32",
|
|
||||||
"64"
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun getHandler(): CommandHandler {
|
|
||||||
return CommandHandler { sender, args ->
|
|
||||||
if (args.isEmpty()) {
|
|
||||||
sender.sendMessage(plugin.langYml.getMessage("needs-player"))
|
|
||||||
return@CommandHandler
|
|
||||||
}
|
|
||||||
if (args.size == 1) {
|
|
||||||
sender.sendMessage(plugin.langYml.getMessage("needs-item"))
|
|
||||||
return@CommandHandler
|
|
||||||
}
|
|
||||||
val receiverName = args[0]
|
|
||||||
val receiver = Bukkit.getPlayer(receiverName)
|
|
||||||
if (receiver == null) {
|
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
|
||||||
return@CommandHandler
|
|
||||||
}
|
|
||||||
val itemID = args[1]
|
|
||||||
var amount = 1
|
|
||||||
val weapon = Weapons.getByID(itemID.lowercase())
|
|
||||||
val fuel = Fuels.getByID(itemID.lowercase())
|
|
||||||
if (weapon == null && fuel == null) {
|
|
||||||
sender.sendMessage(plugin.langYml.getMessage("invalid-item"))
|
|
||||||
return@CommandHandler
|
|
||||||
}
|
|
||||||
var message = plugin.langYml.getMessage("give-success")
|
|
||||||
message = message.replace("%item%", itemID).replace("%recipient%", receiver.name)
|
|
||||||
sender.sendMessage(message)
|
|
||||||
if (args.size == 3) {
|
|
||||||
amount = args[2].toIntOrNull() ?: 1
|
|
||||||
}
|
|
||||||
val item: ItemStack = weapon?.itemStack ?: fuel?.itemStack!!
|
|
||||||
item.amount = amount
|
|
||||||
receiver.inventory.addItem(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTabCompleter(): TabCompleteHandler {
|
|
||||||
return TabCompleteHandler { _, args ->
|
|
||||||
val completions = mutableListOf<String>()
|
|
||||||
|
|
||||||
if (args.isEmpty()) {
|
|
||||||
return@TabCompleteHandler Weapons.values().map { it.id }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size == 1) {
|
|
||||||
StringUtil.copyPartialMatches(
|
|
||||||
args[0],
|
|
||||||
Bukkit.getOnlinePlayers().map { it.name },
|
|
||||||
completions
|
|
||||||
)
|
|
||||||
return@TabCompleteHandler completions
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size == 2) {
|
|
||||||
val itemNames = Weapons.values().map { it.id } union Fuels.values().map { it.id }
|
|
||||||
|
|
||||||
StringUtil.copyPartialMatches(args[1], itemNames, completions)
|
|
||||||
completions.sort()
|
|
||||||
return@TabCompleteHandler completions
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size == 3) {
|
|
||||||
StringUtil.copyPartialMatches(args[2], numbers, completions)
|
|
||||||
return@TabCompleteHandler completions
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.willfp.ecoweapons.commands
|
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
|
||||||
import com.willfp.eco.core.command.impl.Subcommand
|
|
||||||
import com.willfp.eco.core.command.CommandHandler
|
|
||||||
import org.bukkit.command.CommandSender
|
|
||||||
|
|
||||||
class CommandReload(plugin: EcoPlugin) : Subcommand(plugin, "reload", "ecoweapons.command.reload", false) {
|
|
||||||
override fun getHandler(): CommandHandler {
|
|
||||||
return CommandHandler { sender: CommandSender, _: List<String?>? ->
|
|
||||||
plugin.reload()
|
|
||||||
sender.sendMessage(plugin.langYml.getMessage("reloaded"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.willfp.ecoweapons.config
|
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin
|
|
||||||
import com.willfp.eco.core.config.json.JSONStaticBaseConfig
|
|
||||||
import com.willfp.eco.core.config.yaml.YamlBaseConfig
|
|
||||||
|
|
||||||
class EcoWeaponsYml(plugin: EcoPlugin) : YamlBaseConfig("ecoweapons", false, plugin)
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package com.willfp.ecoweapons.weapons
|
|
||||||
|
|
||||||
import com.google.common.collect.BiMap
|
|
||||||
import com.google.common.collect.HashBiMap
|
|
||||||
import com.google.common.collect.ImmutableList
|
|
||||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
|
||||||
import com.willfp.ecoweapons.EcoWeaponsPlugin
|
|
||||||
import com.willfp.ecoweapons.fuels.ConditionHasFuel
|
|
||||||
|
|
||||||
object Weapons {
|
|
||||||
/**
|
|
||||||
* Registered weapons.
|
|
||||||
*/
|
|
||||||
private val BY_ID: BiMap<String, Weapon> = HashBiMap.create()
|
|
||||||
|
|
||||||
val CONDITION_HAS_FUEL = ConditionHasFuel()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all registered [Weapon]s.
|
|
||||||
*
|
|
||||||
* @return A list of all [Weapon]s.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun values(): List<Weapon> {
|
|
||||||
return ImmutableList.copyOf(BY_ID.values)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get [Weapon] matching id.
|
|
||||||
*
|
|
||||||
* @param name The id to search for.
|
|
||||||
* @return The matching [Weapon], or null if not found.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun getByID(name: String): Weapon? {
|
|
||||||
return BY_ID[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update all [Weapon]s.
|
|
||||||
*
|
|
||||||
* @param plugin Instance of EcoWeapons.
|
|
||||||
*/
|
|
||||||
@ConfigUpdater
|
|
||||||
@JvmStatic
|
|
||||||
fun update(plugin: EcoWeaponsPlugin) {
|
|
||||||
for (weapon in values()) {
|
|
||||||
removeWeapon(weapon)
|
|
||||||
}
|
|
||||||
for (setConfig in plugin.ecoWeaponsYml.getSubsections("weapons")) {
|
|
||||||
addNewWeapon(Weapon(setConfig, plugin))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new [Weapon] to EcoWeapons.
|
|
||||||
*
|
|
||||||
* @param weapon The [Weapon] to add.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun addNewWeapon(weapon: Weapon) {
|
|
||||||
BY_ID.remove(weapon.id)
|
|
||||||
BY_ID[weapon.id] = weapon
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove [Weapon] from EcoWeapons.
|
|
||||||
*
|
|
||||||
* @param weapon The [Weapon] to remove.
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun removeWeapon(weapon: Weapon) {
|
|
||||||
BY_ID.remove(weapon.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# EcoWeapons
|
# EcoItems
|
||||||
# by Auxilor
|
# by Auxilor
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
weapons:
|
items:
|
||||||
- id: rogue_zweihander
|
- id: rogue_zweihander
|
||||||
baseDamage: 7
|
baseDamage: 7
|
||||||
baseAttackSpeed: 1.2
|
baseAttackSpeed: 1.2
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
messages:
|
messages:
|
||||||
prefix: "&#ff0000&lEcoWeapons&r &8» &r"
|
prefix: "&#ff0000&lEcoItems&r &8» &r"
|
||||||
no-permission: "&cYou don't have permission to do this!"
|
no-permission: "&cYou don't have permission to do this!"
|
||||||
not-player: "&cThis command must be run by a player"
|
not-player: "&cThis command must be run by a player"
|
||||||
invalid-command: "&cUnknown subcommand!"
|
invalid-command: "&cUnknown subcommand!"
|
||||||
reloaded: "Reloaded! (Restart if you're removed weapons!)"
|
reloaded: "Reloaded! (Restart if you're removed items!)"
|
||||||
needs-player: "&cYou must specify a player"
|
needs-player: "&cYou must specify a player"
|
||||||
invalid-player: "&cInvalid player!"
|
invalid-player: "&cInvalid player!"
|
||||||
needs-item: "&cYou must specify an item!"
|
needs-item: "&cYou must specify an item!"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: EcoWeapons
|
name: EcoItems
|
||||||
version: ${projectVersion}
|
version: ${projectVersion}
|
||||||
main: com.willfp.ecoweapons.EcoWeaponsPlugin
|
main: com.willfp.ecoitems.EcoItemsPlugin
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
authors: [ Auxilor ]
|
authors: [ Auxilor ]
|
||||||
website: willfp.com
|
website: willfp.com
|
||||||
@@ -15,31 +15,30 @@ libraries:
|
|||||||
- 'org.jetbrains.kotlin:kotlin-stdlib:1.6.0'
|
- 'org.jetbrains.kotlin:kotlin-stdlib:1.6.0'
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
ecoweapons:
|
ecoitems:
|
||||||
description: Base Command
|
description: Base Command
|
||||||
permission: ecoweapons.command.ecoweapons
|
permission: ecoitems.command.ecoitems
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
ecoweapons.*:
|
ecoitems.*:
|
||||||
description: All ecoweapons permissions
|
description: All ecoitems permissions
|
||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
ecoweapons.command.*: true
|
ecoitems.command.*: true
|
||||||
ecoweapons.noflydisable: true
|
ecoitems.command.*:
|
||||||
ecoweapons.command.*:
|
|
||||||
description: All commands
|
description: All commands
|
||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
ecoweapons.command.reload: true
|
ecoitems.command.reload: true
|
||||||
ecoweapons.command.ecoweapons: true
|
ecoitems.command.ecoitems: true
|
||||||
ecoweapons.command.give: true
|
ecoitems.command.give: true
|
||||||
|
|
||||||
ecoweapons.command.reload:
|
ecoitems.command.reload:
|
||||||
description: Allows reloading the config
|
description: Allows reloading the config
|
||||||
default: op
|
default: op
|
||||||
ecoweapons.command.give:
|
ecoitems.command.give:
|
||||||
description: Allows the use of /ecoweapons give
|
description: Allows the use of /ecoitems give
|
||||||
default: op
|
default: op
|
||||||
ecoweapons.command.ecoweapons:
|
ecoitems.command.ecoitems:
|
||||||
description: Allows the user of /ecoweapons.
|
description: Allows the user of /ecoitems.
|
||||||
default: true
|
default: true
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 2.6.0
|
version = 3.0.0
|
||||||
plugin-name = EcoWeapons
|
plugin-name = EcoItems
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
rootProject.name = 'EcoWeapons'
|
rootProject.name = 'EcoItems'
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
include ':eco-core'
|
include ':eco-core'
|
||||||
|
|||||||
Reference in New Issue
Block a user