Skip to content

Commit

Permalink
Add config to broadcast ender pearl sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed Dec 27, 2024
1 parent 9f61c54 commit 3e66eda
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ MBedwarsTweaks offers a large amount extra configuration, here are just a few tw
- Permanent arena effects
- Block stat tracking in certain arenas
- Lock team chests
- Broadcast ender pearl sounds

#### 8. So much more!
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void registerEvents() {
manager.registerEvents(new EmptyContainers(), plugin);
manager.registerEvents(new HeightCap(), plugin);
manager.registerEvents(new LockTeamChest(), plugin);
manager.registerEvents(new PearlSoundBroadcast(), plugin);
manager.registerEvents(new PermanentEffects(), plugin);
manager.registerEvents(new PlaceBlocksOnBed(), plugin);
manager.registerEvents(new PlayerLimitBypass(), plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ public class MainConfig {
public static boolean remove_empty_buckets = true;
@Config public static boolean remove_empty_potions = true;

@Config(
description = {
"If enabled, the ender pearl sound will be broadcast to all arena players when a pearl lands"
}
)
public static boolean broadcast_ender_pearl_sound = false;

@Config(
description = {
"Allows players to place blocks on a bed WITHOUT crouching"
Expand Down
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);
}
}
}
}

0 comments on commit 3e66eda

Please sign in to comment.