-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config to broadcast ender pearl sounds
- Loading branch information
1 parent
9f61c54
commit 3e66eda
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/me/metallicgoat/tweaksaddon/tweaks/misc/PearlSoundBroadcast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.metallicgoat.tweaksaddon.tweaks.misc; | ||
|
||
import de.marcely.bedwars.api.GameAPI; | ||
import de.marcely.bedwars.api.arena.Arena; | ||
import de.marcely.bedwars.tools.Helper; | ||
import de.marcely.bedwars.tools.VarSound; | ||
import me.metallicgoat.tweaksaddon.config.MainConfig; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
||
public class PearlSoundBroadcast implements Listener { | ||
|
||
@SuppressWarnings("ConstantConditions") // null warning for the sound | ||
private final static VarSound PEARL_SOUND = VarSound.from(Helper.get().getSoundByName("ENTITY_ENDER_PEARL_THROW")); | ||
|
||
@EventHandler | ||
public void onEntityTeleportEvent(PlayerTeleportEvent event) { | ||
if (!MainConfig.broadcast_ender_pearl_sound || event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) | ||
return; | ||
|
||
final Player teleporter = event.getPlayer(); | ||
final Arena arena = GameAPI.get().getArenaByPlayer(teleporter); | ||
|
||
if (arena == null) | ||
return; | ||
|
||
for (Player player : arena.getPlayers()) { | ||
// "Most sounds can be heard 16 blocks away" (Try 12 it gets quieter) | ||
// https://minecraft.wiki/w/Sound | ||
if (player.getLocation().distance(event.getTo()) > 12) { | ||
PEARL_SOUND.play(player); | ||
} | ||
} | ||
} | ||
} |