From 6100cf94bbe58fdf5472bef04d95abf465b47603 Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Sat, 4 Apr 2020 12:27:17 +0700 Subject: [PATCH] fix powered creepers + change interaction for skipping forward in time --- src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt | 13 +++---------- src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt | 12 +++++++++--- .../pw/hamzantal/bloodmoon/listeners/DeathEvent.kt | 5 ----- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt index 371f0ea..daf772b 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt @@ -12,7 +12,6 @@ object BMData { var bm = BloodMoon.pl val transformed = hashMapOf() - val creepers = mutableListOf() fun ticksLeft(): Int { return (Config.endTime - Config.world.time).toInt() @@ -27,17 +26,12 @@ object BMData { if (en.customName != null) return@forEach animalSpawn(en) } - if (Config.chargedCreepers) Config.world.entities.filter { it is Creeper }.forEach { - (it as Creeper).isPowered = true - creepers += it + if (Config.chargedCreepers) Config.world.entities.filterIsInstance().forEach { + it.isPowered = true } Bukkit.getOnlinePlayers().forEach { it.msg(Config.startMessage.c) } running = true - bm.schedule(delay = ticksLeft() / 20L) { - stop() - Bukkit.getOnlinePlayers().forEach { it.msg(Config.endMessage.c) } - } } fun stop() { @@ -51,8 +45,7 @@ object BMData { } } transformed.clear() - creepers.forEach { it.isPowered = false } - creepers.clear() + Config.world.entities.filterIsInstance().forEach { it.isPowered = false } } fun animalSpawn(en: LivingEntity) { diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt index da04edf..c9d8d85 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt @@ -23,7 +23,8 @@ class BloodMoon : JavaPlugin(), Listener { initListeners() schedule(async = false, period = 1, delay = 1) { - if (Bukkit.getWorlds().first().fullTime - Config.startTime in 0..20) { + val time = Config.world.time + if (time - 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 { @@ -34,11 +35,16 @@ class BloodMoon : JavaPlugin(), Listener { )} (must be between 0 and ${Config.chance}) " ) } + } else if (((Config.endTime > Config.startTime && (time < Config.startTime || time > Config.endTime)) || + (Config.endTime < Config.startTime && (Config.endTime < time && time < Config.startTime))) + && BMData.running + ) { + BMData.stop() + Bukkit.getOnlinePlayers().forEach { it.msg(Config.endMessage.c) } } } command("bloodmoon") { sender, args -> - if (args.isEmpty()) return@command (if (BMData.running) sender.msg("&c&lThe Blood Moon is Active!\n&7${BMData.ticksLeft() / 20} seconds left.") else sender.msg("&a&lThe Blood Moon is not currently active.")) @@ -55,7 +61,7 @@ class BloodMoon : JavaPlugin(), Listener { } "start" -> { - Config.world.time = 13050 + Config.world.time = Config.startTime + 50L sender.msg("&c[!] &7Blood moon has started manually.") BMData.begin() } diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/DeathEvent.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/DeathEvent.kt index 1536f48..75c0c5c 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/DeathEvent.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/DeathEvent.kt @@ -4,11 +4,6 @@ import org.bukkit.event.entity.EntityDeathEvent import pw.hamzantal.bloodmoon.BMData fun onDeath(e: EntityDeathEvent) { - if (BMData.creepers.contains(e.entity)) { - BMData.creepers.remove(e.entity) - return - } - val d = BMData.transformed.keys.firstOrNull { it.entity == e.entity } ?: return d.stopDisguise() BMData.transformed.remove(d)