From cd1e00c78c8d3f367011c63129658eeeab1acd61 Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Fri, 3 Apr 2020 07:37:29 +0700 Subject: [PATCH] make start and end time for blood moon configurable --- src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt | 2 +- src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt | 2 +- src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt | 8 ++++++-- src/main/resources/config.yml | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt index 5dbb31c..371f0ea 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt @@ -15,7 +15,7 @@ object BMData { val creepers = mutableListOf() fun ticksLeft(): Int { - return (23460 - Config.world.time).toInt() + return (Config.endTime - Config.world.time).toInt() } fun begin() { diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt index ae14121..da04edf 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt @@ -23,7 +23,7 @@ class BloodMoon : JavaPlugin(), Listener { initListeners() schedule(async = false, period = 1, delay = 1) { - if (Bukkit.getWorlds().first().fullTime - 13000 in 0..20) { + if (Bukkit.getWorlds().first().fullTime - Config.startTime in 0..20) { val chance = Random.nextDouble() if (!BMData.running && chance < Config.chance) BMData.begin() else Bukkit.getOnlinePlayers().filter { it.hasPermission("bloodmoon.admin") || it.isOp }.forEach { diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt index 5422248..3c79b62 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt @@ -6,8 +6,12 @@ import org.bukkit.Bukkit import org.bukkit.ChatColor object Config : ConfigFile(BloodMoon.pl.dataFolder["config.yml"]) { - private val _world by string("world", "world") - val world get() = Bukkit.getWorld(_world) + private val w by string("world", "world") + val world get() = Bukkit.getWorld(w)!! + val startTime by int("start_time") + val endTime by int("end_time") + + val chance by double("chance", 0.2) val enabledMobs by stringList("transformed_mobs") diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 803166a..3df7c40 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,7 @@ # Which world will the blood moon be enabled for? world: "world" +start_time: 14000 +end_time: 23460 # WHat is the chance that the blood moon will occur on any specific night? chance: 0.2