Skip to content
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

Add Event to control who hears the dragon death sound #10918

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lurkrul <[email protected]>
Date: Wed, 19 Jun 2024 17:57:27 +0800
Subject: [PATCH] Add event so you can modify what players will hear the event


diff --git a/src/main/java/io/papermc/paper/event/entity/DragonPrepareDeathSoundTargetsEvent.java b/src/main/java/io/papermc/paper/event/entity/DragonPrepareDeathSoundTargetsEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..c9f821dd291c486c56597cc32135f481592daeff
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/DragonPrepareDeathSoundTargetsEvent.java
@@ -0,0 +1,99 @@
+package io.papermc.paper.event.entity;
+
+import org.bukkit.entity.Player;
+import org.bukkit.entity.EnderDragon;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.jetbrains.annotations.NotNull;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Is called when an {@link EnderDragon} dies to determine what {@link Player}s hear it.
+ */
+public class DragonPrepareDeathSoundTargetsEvent extends EntityEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+ public Set<Player> playerList;
+
+ public DragonPrepareDeathSoundTargetsEvent(final @NotNull EnderDragon enderDragon, Collection<? extends Player> players) {
+ super(enderDragon);
+ playerList = new HashSet<>(players);
+ }
+
+ /**
Lurkrul marked this conversation as resolved.
Show resolved Hide resolved
+ * The {@link EnderDragon} that fired this event when it died.
+ *
+ * @return the dragon
+ */
+ public EnderDragon getDragon() {
+ return (EnderDragon) super.getEntity();
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lurkrul <[email protected]>
Date: Wed, 19 Jun 2024 17:59:03 +0800
Subject: [PATCH] add event so you can modify what players hear the dragon
death sound


diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
index 4d2fbade3a01ca26ff107f1323ae23db6dad8ef8..43788f3ea1a752e74c1a0be905bc0d1df5fa14c8 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -727,7 +727,11 @@ public class EnderDragon extends Mob implements Enemy {
// CraftBukkit start - Use relative location for far away sounds
// this.level().globalLevelEvent(1028, this.blockPosition(), 0);
int viewDistance = ((ServerLevel) this.level()).getCraftServer().getViewDistance() * 16;
+
+ //paper start - adding control event to determine who hears death sounds
- for (net.minecraft.server.level.ServerPlayer player : this.level().getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ io.papermc.paper.event.entity.DragonPrepareDeathSoundTargetsEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callDragonPrepareDeathSoundEvent((org.bukkit.entity.EnderDragon) this.getBukkitEntity(), this.level().getPlayersForGlobalSoundGamerule());
+ // change the for loop to loop through the players collected in the event. It still respects the global sound events
+ //for (net.minecraft.server.level.ServerPlayer player : this.level().getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ for(org.bukkit.entity.Player bukkitPlayer: event.getPlayerList()) {
+ net.minecraft.server.level.ServerPlayer player = ((org.bukkit.craftbukkit.entity.CraftPlayer)bukkitPlayer).getHandle();
+ //paper end - adding control event to determine who hears death sounds
double deltaX = this.getX() - player.getX();
double deltaZ = this.getZ() - player.getZ();
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index bd6fee3e3ad9116802ff8bb57bfa741b881c4057..f225942db664b8ce6f97dd907f39daca5b85fc9b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -2204,4 +2200,21 @@ public class CraftEventFactory {
return event;
}
// Paper end - add EntityFertilizeEggEvent
+
+ // Paper start - add DragonPrepareDeathSoundTargetsEvent
+ /**
+ * Calls {@link io.papermc.paper.event.entity.DragonPrepareDeathSoundTargetsEvent}
+ * Listeners can add and remove players from the list of players that will hear the dragon death sound.
+ *
+ * @param dragon the EnderDragon that has died
+ * @param players the players that are origionally intended to hear the death sound.
+ * @return the event after it was called. This will be used to retrieve the list of players that will hear the death sound
+ */
+ public static io.papermc.paper.event.entity.DragonPrepareDeathSoundTargetsEvent callDragonPrepareDeathSoundEvent(org.bukkit.entity.EnderDragon dragon, List<net.minecraft.server.level.ServerPlayer> players) {
+ io.papermc.paper.event.entity.DragonPrepareDeathSoundTargetsEvent event = new io.papermc.paper.event.entity.DragonPrepareDeathSoundTargetsEvent(dragon, players.stream().map(element->element.getBukkitEntity().getPlayer()).collect(Collectors.toCollection(java.util.HashSet::new)));
+ event.callEvent();
+ return event;
+ }
+ // Paper end - add DragonPrepareDeathSoundTargetsEvent
}