-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-352 Add Arc Riders style flare - firework - indicating players death location #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
955c884
df8cbc9
2b4707f
f65f021
5e1c63b
9aad758
b820c43
e24da46
af466cd
8a05d4c
63d4172
3502187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package com.eternalcode.combat.fight.death; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.event.CauseOfUnTag; | ||
| import com.eternalcode.combat.fight.event.FightUntagEvent; | ||
| import com.eternalcode.commons.scheduler.Scheduler; | ||
| import java.time.Duration; | ||
| import java.util.UUID; | ||
| import org.bukkit.Color; | ||
| import org.bukkit.FireworkEffect; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.NamespacedKey; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.World; | ||
| import org.bukkit.entity.Firework; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
| import org.bukkit.event.entity.PlayerDeathEvent; | ||
| import org.bukkit.inventory.meta.FireworkMeta; | ||
| import org.bukkit.persistence.PersistentDataType; | ||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| public class DeathFlareController implements Listener { | ||
|
|
||
| private final PluginConfig pluginConfig; | ||
| private final Server server; | ||
| private final Scheduler scheduler; | ||
| private final NamespacedKey key; | ||
|
|
||
| public DeathFlareController(PluginConfig pluginConfig, Server server, Scheduler scheduler, Plugin plugin) { | ||
| this.pluginConfig = pluginConfig; | ||
| this.server = server; | ||
| this.scheduler = scheduler; | ||
| this.key = NamespacedKey.fromString("eternalcombat_firework", plugin); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| public void onFightUntagEvent(FightUntagEvent event) { | ||
| CauseOfUnTag cause = event.getCause(); | ||
| if (cause != CauseOfUnTag.DEATH && cause != CauseOfUnTag.DEATH_BY_PLAYER) { | ||
| return; | ||
| } | ||
|
|
||
| UUID uniqueId = event.getPlayer(); | ||
| Player player = this.server.getPlayer(uniqueId); | ||
|
|
||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.pluginConfig.death.firework.inCombat && !this.pluginConfig.death.firework.afterEveryDeath) { | ||
| this.spawnFlare(player); | ||
| } | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| public void onPlayerDeathEventFlare(PlayerDeathEvent event) { | ||
| Player player = event.getEntity(); | ||
|
|
||
| if (this.pluginConfig.death.firework.afterEveryDeath) { | ||
| this.spawnFlare(player); | ||
| } | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | ||
| if (event.getDamager() instanceof Firework firework && firework.getPersistentDataContainer().has(key, PersistentDataType.STRING)) { | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
|
|
||
| private void spawnFlare(Player player) { | ||
| Location deathLocation = player.getLocation(); | ||
| World world = deathLocation.getWorld(); | ||
|
|
||
| Firework flare = world.spawn(deathLocation, Firework.class); | ||
| flare.getPersistentDataContainer().set(key, PersistentDataType.STRING, "true"); | ||
|
|
||
| FireworkMeta meta = flare.getFireworkMeta(); | ||
|
|
||
| Color primaryColor = this.decodeColor(this.pluginConfig.death.firework.primaryColor, "primary"); | ||
| Color fadeColor = this.decodeColor(this.pluginConfig.death.firework.fadeColor, "fade"); | ||
|
|
||
| FireworkEffect effect = FireworkEffect.builder() | ||
| .with(this.pluginConfig.death.firework.fireworkType) | ||
| .withColor(primaryColor) | ||
| .withFade(fadeColor) | ||
| .trail(true) | ||
| .flicker(true) | ||
| .build(); | ||
|
|
||
| meta.addEffect(effect); | ||
| meta.setPower(this.pluginConfig.death.firework.power); | ||
| flare.setFireworkMeta(meta); | ||
|
|
||
| if (this.pluginConfig.death.firework.particlesEnabled) { | ||
| scheduleParticles(flare, world); | ||
| } | ||
| } | ||
|
|
||
| private void scheduleParticles(Firework flare, World world) { | ||
| this.scheduler.runLaterAsync( | ||
| () -> { | ||
| if (flare.isDead() || !flare.isValid()) { | ||
| return; | ||
| } | ||
| this.spawnParticles(world, flare); | ||
| this.scheduleParticles(flare, world); | ||
| }, Duration.ofMillis(50) | ||
| ); | ||
| } | ||
|
|
||
| private Color decodeColor(String firework, String name) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest enum ColorType instead of plain string
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enum does not cover all rgb types plus it's highly limited - this is bukkit enum not the java.awt one |
||
| try { | ||
| return Color.fromRGB(Integer.decode(firework)); | ||
| } | ||
| catch (NumberFormatException exception) { | ||
| throw new IllegalArgumentException( | ||
| "Invalid " + name + " format in plugin configuration" + firework, | ||
| exception | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| private void spawnParticles(World world, Firework flare) { | ||
| Location location = flare.getLocation(); | ||
|
|
||
| world.spawnParticle( | ||
| this.pluginConfig.death.firework.mainParticle.get(), | ||
| location, | ||
| this.pluginConfig.death.firework.mainParticleCount, | ||
| 0.05, | ||
| 0.05, | ||
| 0.05, | ||
| 0.01 | ||
| ); | ||
|
|
||
| world.spawnParticle( | ||
| this.pluginConfig.death.firework.secondaryParticle.get(), | ||
| location, | ||
| this.pluginConfig.death.firework.secondaryParticleCount, | ||
| 0.1, | ||
| 0.1, | ||
| 0.1, | ||
| 0.01 | ||
| ); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.eternalcode.combat.fight.death; | ||
|
|
||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||
| import com.eternalcode.combat.fight.event.CauseOfUnTag; | ||
| import com.eternalcode.combat.fight.event.FightUntagEvent; | ||
| import java.util.UUID; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.entity.PlayerDeathEvent; | ||
|
|
||
| public class DeathLightningController implements Listener { | ||
|
|
||
| private final PluginConfig pluginConfig; | ||
| private final Server server; | ||
|
|
||
| public DeathLightningController(PluginConfig pluginConfig, Server server) { | ||
| this.pluginConfig = pluginConfig; | ||
| this.server = server; | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| public void onFightUntagEvent(FightUntagEvent event) { | ||
| CauseOfUnTag cause = event.getCause(); | ||
| if (cause != CauseOfUnTag.DEATH && cause != CauseOfUnTag.DEATH_BY_PLAYER) { | ||
| return; | ||
| } | ||
|
|
||
| UUID uniqueId = event.getPlayer(); | ||
| Player player = this.server.getPlayer(uniqueId); | ||
|
|
||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.pluginConfig.death.lightning.inCombat && !this.pluginConfig.death.lightning.afterEveryDeath) { | ||
| this.lightningStrike(player); | ||
CitralFlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
| public void onPlayerDeathEventLightning(PlayerDeathEvent event) { | ||
| Player player = event.getEntity(); | ||
|
|
||
| if (this.pluginConfig.death.lightning.afterEveryDeath) { | ||
| lightningStrike(player); | ||
| } | ||
| } | ||
|
|
||
| private void lightningStrike(Player player) { | ||
| player.getWorld().strikeLightningEffect(player.getLocation()); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,77 @@ | ||
| package com.eternalcode.combat.fight.death; | ||
|
|
||
| import com.cryptomorin.xseries.particles.XParticle; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import eu.okaeri.configs.annotation.Comment; | ||
| import org.bukkit.FireworkEffect; | ||
|
|
||
| public class DeathSettings extends OkaeriConfig { | ||
|
|
||
| @Comment("Should lightning strike when a player dies") | ||
| public boolean lightning = true; | ||
CitralFlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Comment({ | ||
| "Settings related to lightning effect upon death", | ||
| "Setting both afterEveryDeath and inCombat to false will disable this feature completely" | ||
| }) | ||
CitralFlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public LightningSettings lightning = new LightningSettings(); | ||
|
|
||
| public static class LightningSettings extends OkaeriConfig { | ||
|
|
||
| @Comment("Should lightning spawn on every death?") | ||
| public boolean afterEveryDeath = false; | ||
|
|
||
| @Comment("Should lightning spawn on ONLY deaths in combat?") | ||
| public boolean inCombat = true; | ||
| } | ||
|
|
||
| @Comment({ | ||
| "Settings for the Arc Raiders style flare (firework)", | ||
| "Setting both afterEveryDeath and inCombat to false will disable this feature completely" | ||
| }) | ||
CitralFlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public FlareSettings firework = new FlareSettings(); | ||
|
|
||
| public static class FlareSettings extends OkaeriConfig { | ||
|
|
||
| @Comment("Should firework (flare) spawn on every death?") | ||
| public boolean afterEveryDeath = false; | ||
|
|
||
| @Comment("Should firework (flare) spawn on ONLY deaths in combat?") | ||
| public boolean inCombat = false; | ||
|
|
||
| @Comment("Power of firework - how long till explosion (please enter positive number)") | ||
| public int power = 2; | ||
|
|
||
| @Comment({ | ||
| "The firework (flare) effect type (BALL, BALL_LARGE, STAR, BURST, CREEPER)", | ||
| "Reference: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/FireworkEffect.Type.html" | ||
| }) | ||
| public FireworkEffect.Type fireworkType = FireworkEffect.Type.BALL; | ||
|
|
||
| @Comment("Hex color for the firework (flare)") | ||
| public String primaryColor = "#a80022"; | ||
|
|
||
| @Comment("Hex color for the fade of firework (flare)") | ||
| public String fadeColor = "#0a0a0a"; | ||
|
|
||
| @Comment("Toggle on/off additional particles spawned in the firework (flare) path") | ||
| public boolean particlesEnabled = true; | ||
|
|
||
| @Comment({ | ||
| "The main trail particle (e.g., CAMPFIRE_COSY_SMOKE, SMOKE_LARGE)", | ||
| "Reference: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html" | ||
| }) | ||
| public XParticle mainParticle = XParticle.CAMPFIRE_COSY_SMOKE; | ||
|
|
||
| @Comment("Count of main particles spawned on each tick") | ||
| public int mainParticleCount = 3; | ||
|
|
||
| @Comment({ | ||
| "The secondary trail particle (e.g., CAMPFIRE_COSY_SMOKE, SMOKE_LARGE)", | ||
| "Reference: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html" | ||
| }) | ||
|
|
||
| public XParticle secondaryParticle = XParticle.SMALL_FLAME; | ||
|
|
||
| @Comment("Count of secondary particles spawned on each tick") | ||
| public int secondaryParticleCount = 3; | ||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.