From 9e48dda4cae498bd8076406fa0a9e7ea4b71e35e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Mar 2022 19:56:09 +0000 Subject: [PATCH] General improvements --- .../ecocrates/commands/CommandEcoCrates.kt | 1 + .../ecocrates/commands/CommandForceOpen.kt | 42 +++++++++++++++++++ .../com/willfp/ecocrates/crate/Crate.kt | 6 +-- .../com/willfp/ecocrates/reward/Reward.kt | 13 +++--- .../core-plugin/src/main/resources/crates.yml | 7 +++- .../core-plugin/src/main/resources/plugin.yml | 5 +++ 6 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandForceOpen.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandEcoCrates.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandEcoCrates.kt index d76fb03..2a02587 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandEcoCrates.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandEcoCrates.kt @@ -17,6 +17,7 @@ class CommandEcoCrates(plugin: EcoPlugin) : PluginCommand( .addSubcommand(CommandGive(plugin)) .addSubcommand(CommandKeys(plugin)) .addSubcommand(CommandSet(plugin)) + .addSubcommand(CommandForceOpen(plugin)) } override fun onExecute(sender: CommandSender, args: List) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandForceOpen.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandForceOpen.kt new file mode 100644 index 0000000..c97c84d --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/commands/CommandForceOpen.kt @@ -0,0 +1,42 @@ +package com.willfp.ecocrates.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.ecocrates.crate.Crates +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandForceOpen(plugin: EcoPlugin) : Subcommand( + plugin, + "forceopen", + "ecocrates.command.forceopen", + true +) { + override fun onExecute(player: CommandSender, args: List) { + player as Player + val crate = Crates.getByID(args[0]) ?: return + + crate.open(player) + } + + override fun tabComplete(sender: CommandSender, args: List): List { + val completions = mutableListOf() + + if (args.isEmpty()) { + return Crates.values().map { it.id } + } + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Crates.values().map { it.id }, + completions + ) + + return completions + } + + return emptyList() + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt index e5b6087..18417de 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/Crate.kt @@ -76,8 +76,8 @@ class Crate( } } - private val onFinishSound = PlayableSound( - config.getSubsections("onFinish.sounds") + private val finishSound = PlayableSound( + config.getSubsections("finish.sounds") .map { ConfiguredSound.fromConfig(it) } ) @@ -180,7 +180,7 @@ class Crate( fun handleFinish(player: Player, roll: Roll) { roll.reward.giveTo(player) - onFinishSound.play(player.location) + finishSound.play(player.location) } fun giveKeys(player: OfflinePlayer, amount: Int) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/reward/Reward.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/reward/Reward.kt index 2f4451f..18ff199 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/reward/Reward.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/reward/Reward.kt @@ -7,20 +7,21 @@ import com.willfp.eco.core.items.builder.ItemStackBuilder import com.willfp.eco.core.recipe.parts.EmptyTestableItem import org.bukkit.Bukkit import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack class Reward( - private val config: Config + config: Config ) { - val commands = config.getStrings("commands") + private val commands = config.getStrings("commands") - val items = config.getStrings("items").map { Items.lookup(it) }.filterNot { it is EmptyTestableItem } + private val items = config.getStrings("items").map { Items.lookup(it) }.filterNot { it is EmptyTestableItem } - val display = ItemStackBuilder(Items.lookup(config.getString("display.item"))) + private val messages = config.getFormattedStrings("messages") + + val display: ItemStack = ItemStackBuilder(Items.lookup(config.getString("display.item"))) .addLoreLines(config.getStrings("display.lore")) .build() - val messages = config.getFormattedStrings("messages") - val weight = config.getDouble("weight.actual") val displayWeight = config.getDouble("weight.display") diff --git a/eco-core/core-plugin/src/main/resources/crates.yml b/eco-core/core-plugin/src/main/resources/crates.yml index 4dd77ef..16307c2 100644 --- a/eco-core/core-plugin/src/main/resources/crates.yml +++ b/eco-core/core-plugin/src/main/resources/crates.yml @@ -2,6 +2,7 @@ crates: - id: demo name: "Demo Crate" roll: csgo + preview: title: Demo Crate rows: 6 @@ -15,6 +16,7 @@ crates: - "100000001" - "100000001" - "111111111" + keygui: item: tripwire_hook unbreaking:1 hide_enchants name:"Demo Crate" lore: @@ -24,6 +26,7 @@ crates: column: 3 rightClickMessage: - "Buy a Demo Crate key here! get lured into the trap of gambling addiction" + placed: particles: - particle: flame @@ -34,11 +37,13 @@ crates: - "Amogus? Sus!" - "&b&lLeft Click to Preview" - '&a&lRight click to Open' - onFinish: + + finish: sounds: - sound: entity_firework_rocket_launch volume: 100 pitch: 1 + rewards: - commands: [ ] items: diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 631796d..3b733be 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ commands: ecocrates: aliases: - crates + - crate description: Base plugin command permission: ecocrates.command.ecocrates @@ -28,6 +29,7 @@ permissions: ecocrates.command.preview: true ecocrates.command.keys: true ecocrates.command.set: true + ecocrates.command.forceopen: true ecocrates.break: true ecocrates.command.ecocrates: @@ -42,6 +44,9 @@ permissions: ecocrates.command.open: description: Allows opening crates with /ecocrates open default: true + ecocrates.command.forceopen: + description: Allows opening crates with /ecocrates forceopen + default: op ecocrates.command.preview: description: Allows previewing crates with /ecocrates preview default: true