fix powered creepers + change interaction for skipping forward in time

master
ALI Hamza 2020-04-04 12:27:17 +07:00
parent cd1e00c78c
commit 6100cf94bb
No known key found for this signature in database
GPG Key ID: BCA8A46C87798C4C
3 changed files with 12 additions and 18 deletions

@ -12,7 +12,6 @@ object BMData {
var bm = BloodMoon.pl
val transformed = hashMapOf<MobDisguise, LivingEntity>()
val creepers = mutableListOf<Creeper>()
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<Creeper>().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<Creeper>().forEach { it.isPowered = false }
}
fun animalSpawn(en: LivingEntity) {

@ -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()
}

@ -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)