Skip to content

Commit

Permalink
feat: remove showMessage from enderpearl & crafting modules, relying …
Browse files Browse the repository at this point in the history
…on empty to disable
  • Loading branch information
kernitus committed Dec 26, 2024
1 parent 02ec0c4 commit a57bfab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import org.bukkit.event.inventory.PrepareItemCraftEvent
*/
class ModuleDisableCrafting(plugin: OCMMain) : OCMModule(plugin, "disable-crafting") {
private lateinit var denied: List<Material>
private var message: String? = null
private var message: String = ""

init {
reload()
}

override fun reload() {
denied = loadMaterialList(module(), "denied")
message = if (module().getBoolean("showMessage")) module().getString("message") else null
message = module().getString("message") ?: ""
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand All @@ -41,8 +41,8 @@ class ModuleDisableCrafting(plugin: OCMMain) : OCMModule(plugin, "disable-crafti

if (result != null && denied.contains(result.type)) {
inv.result = null
if (message != null) viewers.forEach {
send(it, message!!)
if (message.isNotBlank()) viewers.forEach {
send(it, message)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ModuleDisableEnderpearlCooldown(plugin: OCMMain) : OCMModule(plugin, "disa
private val ignoredPlayers: MutableSet<UUID> = HashSet()
private var lastLaunched: MutableMap<UUID, Long>? = null
private var cooldown = 0
private var message: String? = null
private var message: String = ""

companion object {
lateinit var instance: ModuleDisableEnderpearlCooldown
Expand All @@ -47,7 +47,7 @@ class ModuleDisableEnderpearlCooldown(plugin: OCMMain) : OCMModule(plugin, "disa
if (lastLaunched == null) lastLaunched = WeakHashMap()
} else lastLaunched = null

message = if (module().getBoolean("showMessage")) module().getString("message") else null
message = module().getString("message") ?: ""
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand All @@ -69,8 +69,8 @@ class ModuleDisableEnderpearlCooldown(plugin: OCMMain) : OCMModule(plugin, "disa
lastLaunched?.get(uuid)?.let { lastLaunchedValue ->
val elapsedSeconds = currentTime - lastLaunchedValue
if (elapsedSeconds < cooldown) {
message?.let {
send(shooter, it, cooldown - elapsedSeconds)
if (message.isNotBlank()) {
send(shooter, message, cooldown - elapsedSeconds)
return
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ disable-crafting:
# List of denied items
denied:
- shield
# Show the user a message if they try to craft a blacklisted item
showMessage: true
message: "&cYou cannot craft that item!"

disable-offhand:
Expand All @@ -480,8 +478,6 @@ disable-enderpearl-cooldown:
# The cooldown, in seconds
# PlaceholderAPI: %ocm_enderpearl_cooldown%
cooldown: 0
# Show the user a message if they try to use an enderpearl and the cooldown has not expired yet
showMessage: true
message: "&cYou must wait &7%ds&c before using an enderpearl again!"

chorus-fruit:
Expand Down

0 comments on commit a57bfab

Please sign in to comment.