Skip to content

Commit

Permalink
Disable damage for pgm-spawned fireworks (#1445)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Nov 26, 2024
1 parent 9733fb3 commit 28b6734
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions core/src/main/java/tc/oc/pgm/fireworks/FireworkMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.metadata.FixedMetadataValue;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchModule;
Expand Down Expand Up @@ -94,10 +96,9 @@ private static class FireworkRunner implements Runnable {
public FireworkRunner(Match match, Collection<Competitor> winners) {
this.match = match;
this.winners = winners;
this.colors =
winners.stream()
.map(winner -> BukkitUtils.colorOf(winner.getColor()))
.collect(Collectors.toSet());
this.colors = winners.stream()
.map(winner -> BukkitUtils.colorOf(winner.getColor()))
.collect(Collectors.toSet());
}

@Override
Expand All @@ -113,15 +114,14 @@ public void run() {

Type type = FIREWORK_TYPES.get(match.getRandom().nextInt(FIREWORK_TYPES.size()));

FireworkEffect effect =
FireworkEffect.builder()
.with(type)
.withFlicker()
.withColor(this.colors)
.withFade(Color.BLACK)
.build();
FireworkEffect effect = FireworkEffect.builder()
.with(type)
.withFlicker()
.withColor(this.colors)
.withFade(Color.BLACK)
.build();

spawnFirework(player.getBukkit().getLocation(), effect, ROCKET_POWER);
spawnFirework(player.getLocation(), effect, ROCKET_POWER);
}
}
this.iterations++;
Expand Down Expand Up @@ -213,16 +213,22 @@ public void onFlagCapture(final FlagCaptureEvent event) {
}
}

private static final String FIREWORK_METADATA = "pgm-custom-firework";

@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {
if (event.getDamager().hasMetadata(FIREWORK_METADATA)) event.setCancelled(true);
}

public void spawnFireworkDisplay(
Location center, Color color, int count, double radius, int power) {
if (Double.isInfinite(radius)) return;
FireworkEffect effect =
FireworkEffect.builder()
.with(Type.BURST)
.withFlicker()
.withColor(color)
.withFade(Color.BLACK)
.build();
FireworkEffect effect = FireworkEffect.builder()
.with(Type.BURST)
.withFlicker()
.withColor(color)
.withFade(Color.BLACK)
.build();

for (int i = 0; i < count; i++) {
double angle = 2 * Math.PI / count * i;
Expand Down Expand Up @@ -253,6 +259,7 @@ public static Firework spawnFirework(Location location, FireworkEffect effect, i

Firework firework = (Firework) location.getWorld().spawnEntity(location, FIREWORK_ENTITY);
firework.setFireworkMeta(meta);
firework.setMetadata(FIREWORK_METADATA, new FixedMetadataValue(PGM.get(), true));

return firework;
}
Expand Down

0 comments on commit 28b6734

Please sign in to comment.