diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..08411c7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,19 @@ +image: java:8-jdk + +before_script: + - chmod 777 ./* + +stages: + - build + +build: + stage: build + script: + - ./gradlew clean shadowJar + artifacts: + name: latest + paths: + - ./build/libs/*.jar + expire_in: 50 yrs + only: + - master diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt index f2243dc..5dbb31c 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BMData.kt @@ -20,21 +20,12 @@ object BMData { fun begin() { stop() - println(Config.enabledMobs) Config.world.entities.forEach { en -> - if (!Config.enabledMobs.contains(en.type.toString().toUpperCase())) { + if (!Config.enabledMobs.contains(en.type.toString().toUpperCase()) || en !is LivingEntity) { return@forEach } - en.remove() - val blood = en.world.spawnEntity(en.location, EntityType.ZOMBIE).apply { - (this as Zombie).isBaby = true - customName = "§cBlood ${en.name}" - isCustomNameVisible = true - } - val disguise = MobDisguise(DisguiseType.valueOf(en.type.name)) - disguise.entity = blood - disguise.startDisguise() - transformed[disguise] = en as LivingEntity + if (en.customName != null) return@forEach + animalSpawn(en) } if (Config.chargedCreepers) Config.world.entities.filter { it is Creeper }.forEach { (it as Creeper).isPowered = true @@ -50,7 +41,6 @@ object BMData { } fun stop() { - println("stopping...") running = false transformed.forEach { (d, e) -> d.entity.remove() @@ -64,4 +54,17 @@ object BMData { creepers.forEach { it.isPowered = false } creepers.clear() } + + fun animalSpawn(en: LivingEntity) { + en.remove() + val blood = en.world.spawnEntity(en.location, EntityType.ZOMBIE).apply { + (this as Zombie).isBaby = true + customName = Config.bloodAnimalName.replace("%t%", en.name).c + isCustomNameVisible = true + } + val disguise = MobDisguise(DisguiseType.valueOf(en.type.name)) + disguise.entity = blood + disguise.startDisguise() + transformed[disguise] = en + } } \ No newline at end of file diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt index d1596fc..17467ab 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/BloodMoon.kt @@ -26,16 +26,41 @@ class BloodMoon : JavaPlugin(), Listener { if (Bukkit.getWorlds().first().fullTime - 13000 in 0..20) { val chance = Random.nextDouble() if (!BMData.running && chance < Config.chance) BMData.begin() - else Bukkit.getOnlinePlayers().filter { it.isOp }.forEach { - it.msg("&c[!] &7Blood Moon chance did not meet threshold: ${String.format("%.02f", chance)} (must be between 0 and ${Config.chance}) ") + else Bukkit.getOnlinePlayers().filter { it.hasPermission("bloodmoon.admin") }.forEach { + it.msg( + "&c[!] &7Blood Moon chance did not meet threshold: ${String.format( + "%.02f", + chance + )} (must be between 0 and ${Config.chance}) " + ) } } } -command("bloodmoon") { sender, _ -> - 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.") -} + command("bloodmoon") { sender, args -> + + if (args.isEmpty()) + 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.") + + if (!sender.hasPermission("bloodmoon.admin")) { + sender.msg("&cNo permission!") + return@command + } + + when (args.component1().toLowerCase()) { + "stop" -> { + sender.msg("&c[!] &7Blood moon has stopped.") + BMData.stop() + } + + "start" -> { + Config.world.time = 13050 + sender.msg("&c[!] &7Blood moon has started manually.") + BMData.begin() + } + } + } } override fun onDisable() { diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt index 35b50ea..5422248 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/Config.kt @@ -17,6 +17,7 @@ object Config : ConfigFile(BloodMoon.pl.dataFolder["config.yml"]) { val startMessage by string("startMessage", "&c&lThe blood moon has now started".c) val endMessage by string("endMessage", "&cThe blood moon is now over".c) + val bloodAnimalName by string ("bloodAnimalNames", "&c&lBlood %t%") } val String.c get() = ChatColor.translateAlternateColorCodes('&', this) \ No newline at end of file diff --git a/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/SpecialSpawning.kt b/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/SpecialSpawning.kt index e305de3..4d4f14e 100644 --- a/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/SpecialSpawning.kt +++ b/src/main/kotlin/pw/hamzantal/bloodmoon/listeners/SpecialSpawning.kt @@ -1,5 +1,7 @@ package pw.hamzantal.bloodmoon.listeners +import me.libraryaddict.disguise.disguisetypes.DisguiseType +import me.libraryaddict.disguise.disguisetypes.MobDisguise import org.bukkit.entity.Creeper import org.bukkit.entity.EntityType import org.bukkit.entity.Spider @@ -15,11 +17,7 @@ val surrounding = listOf( 0.0 to -1.0, 0.0 to 1.0, 1.0 to -1.0, - 1.0 to 0.0, - 1.0 to 1.0, - -1.0 to -1.0, - -1.0 to -0.0, - -1.0 to 1.0 + 1.0 to 0.0 ) fun onCreatureSpawn(e: CreatureSpawnEvent) { @@ -39,5 +37,9 @@ fun onCreatureSpawn(e: CreatureSpawnEvent) { en.addPotionEffect(PotionEffect(PotionEffectType.SPEED, BMData.ticksLeft(), 3, true, true)) en.addPotionEffect(PotionEffect(PotionEffectType.INCREASE_DAMAGE, BMData.ticksLeft(), 1, true, true)) } + else -> { + if (!Config.enabledMobs.contains(en.type.toString().toUpperCase())) return + BMData.animalSpawn(en) + } } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4748d50..803166a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,4 +22,5 @@ strongSpiders: true #Starting and ending messages startMessage: "&c&lThe blood moon has now started" -endMessage: "&cThe blood moon is now over" \ No newline at end of file +endMessage: "&cThe blood moon is now over" +bloodAnimalNames: "&c&lBlood %t%" \ No newline at end of file