From 0b5ad55a211e766ceb5a223bbefd2d6db9f7e674 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 29 Apr 2022 22:33:26 +0100 Subject: [PATCH] Added activation/expiry commands --- .../src/main/kotlin/com/willfp/boosters/BoosterUtils.kt | 7 +++++++ .../main/kotlin/com/willfp/boosters/BoostersPlugin.kt | 7 +++++++ .../main/kotlin/com/willfp/boosters/boosters/Booster.kt | 4 ++++ eco-core/core-plugin/src/main/resources/boosters.yml | 9 +++++++++ 4 files changed, 27 insertions(+) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt index 46cbcd7..203572d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt @@ -52,6 +52,13 @@ fun Player.activateBooster(booster: Booster): Boolean { Bukkit.broadcastMessage(activationMessage) } + for (expiryCommand in booster.activationCommands) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + expiryCommand.replace("%player%", booster.active?.player?.name ?: "") + ) + } + ServerProfile.load().write( booster.expiryTimeKey, (booster.duration.toDouble() * 50) + System.currentTimeMillis() diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt index 37d1005..fd750e7 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt @@ -36,6 +36,13 @@ class BoostersPlugin : LibReforgePlugin(2036, 14269, "&e") { Bukkit.broadcastMessage(expiryMessage) } + for (expiryCommand in booster.expiryMessages) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + expiryCommand.replace("%player%", booster.active?.player?.name ?: "") + ) + } + Bukkit.getServer().expireBooster(booster) } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt index 50a9eed..249076e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt @@ -89,6 +89,10 @@ class Booster( val expiryMessages: List = config.getFormattedStrings("messages.expiry") + val activationCommands: List = config.getFormattedStrings("commands.activation") + + val expiryCommands: List = config.getFormattedStrings("commands.expiry") + fun getGuiItem(player: Player): ItemStack { return ItemStackBuilder(Items.lookup(config.getString("gui.item"))) .setDisplayName(config.getFormattedString("gui.name")) diff --git a/eco-core/core-plugin/src/main/resources/boosters.yml b/eco-core/core-plugin/src/main/resources/boosters.yml index 3e1d39f..66c075d 100644 --- a/eco-core/core-plugin/src/main/resources/boosters.yml +++ b/eco-core/core-plugin/src/main/resources/boosters.yml @@ -7,6 +7,9 @@ boosters: args: multiplier: 1.5 conditions: [] + commands: + activation: [] + expiry: [] messages: activation: - "" @@ -45,6 +48,9 @@ boosters: args: multiplier: 2 conditions: [] + commands: + activation: [] + expiry: [] messages: activation: - "" @@ -83,6 +89,9 @@ boosters: args: multiplier: 2 conditions: [] + commands: + activation: [] + expiry: [] messages: activation: - ""