From f91d46a645e598c60bf01233d2ddea9cda5620e3 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Mon, 10 Jan 2022 19:03:39 +0300 Subject: [PATCH] Added commands support to Eye Of The Depth effect (command::ban %player%) --- .../effects/effects/EffectEyeOfTheDepths.kt | 46 +++++++++++++++---- .../src/main/resources/effects.yml | 2 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEyeOfTheDepths.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEyeOfTheDepths.kt index 776e8cb..2dca598 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEyeOfTheDepths.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEyeOfTheDepths.kt @@ -5,9 +5,13 @@ import com.willfp.eco.core.items.Items import com.willfp.eco.util.NumberUtils import com.willfp.ecoskills.effects.Effect import com.willfp.ecoskills.getEffectLevel +import org.bukkit.Bukkit +import org.bukkit.Location +import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.player.PlayerFishEvent +import org.bukkit.inventory.ItemStack class EffectEyeOfTheDepths: Effect( "eye_of_the_depths" @@ -38,13 +42,39 @@ class EffectEyeOfTheDepths: Effect( val items = config.getStrings("rare-loot-items") - val itemName = items[NumberUtils.randInt(0, items.size - 1)] + val reward = items[NumberUtils.randInt(0, items.size - 1)] - val item = Items.lookup(itemName).item - - DropQueue(player) - .setLocation(event.caught!!.location) - .addItem(item) - .push() + LootReward.fromString(reward).reward(player, event.caught!!.location) } -} \ No newline at end of file + + class LootReward( + private val item: ItemStack? = null, + private val command: String? = null + ) + { + companion object { + @JvmStatic + fun fromString(from: String): LootReward { + return if (from.startsWith("command::", true)) { + LootReward(command = from.replace("command::", "").replace("command:: ", "")) + } else { + LootReward(item = Items.lookup(from).item) + } + } + } + + fun reward(player: Player, location: Location = player.location) { + if (item != null) { + DropQueue(player) + .setLocation(location) + .addItem(item) + .push() + } + else { + command?.let { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), it.replace("%player%", player.name)) } + } + + } + } +} + diff --git a/eco-core/core-plugin/src/main/resources/effects.yml b/eco-core/core-plugin/src/main/resources/effects.yml index 798f48f..87f3441 100644 --- a/eco-core/core-plugin/src/main/resources/effects.yml +++ b/eco-core/core-plugin/src/main/resources/effects.yml @@ -30,7 +30,7 @@ eye_of_the_depths: # Disabled worlds disabled-in-worlds: [] - rare-loot-items: + rare-loot-items: # Either an item from items lookup system, or a command (- command: say %player% is cool) - enchanted_book confusion:1 - enchanted_book confusion:2 - netherite_ingot